dleslie 00/07/27 11:13:15
Added: java/samples/UseStylesheetParam foo.xml foo.xsl readme.html
UseStylesheetParam.java
Log:
xalan-j 2.0 sample app.
Revision Changes Path
1.1 xml-xalan/java/samples/UseStylesheetParam/foo.xml
Index: foo.xml
===================================================================
<?xml version="1.0"?>
<doc>Hello</doc>
1.1 xml-xalan/java/samples/UseStylesheetParam/foo.xsl
Index: foo.xsl
===================================================================
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:param name="param1" select="'default value'"/>
<xsl:template match="doc">
<out><xsl:value-of select="$param1"/></out>
</xsl:template>
</xsl:stylesheet>
1.1 xml-xalan/java/samples/UseStylesheetParam/readme.html
Index: readme.html
===================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Xalan Samples</title>
</head>
<body>
<h2>Xalan Samples</h2>
<p>For information about the samples (what they illustrate and how to run
them), see <a href="../../docs/samples.html">Samples</a>.</p>
</body>
</html>
1.1
xml-xalan/java/samples/UseStylesheetParam/UseStylesheetParam.java
Index: UseStylesheetParam.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "XSLT4J" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
// Imported TraX classes
import trax.Processor;
import trax.Templates;
import trax.Transformer;
import trax.Result;
import trax.ProcessorException;
import trax.ProcessorFactoryException;
import trax.TransformException;
// Imported SAX classes
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
// Imported java classes
import java.io.FileWriter;
import java.io.IOException;
/**
* Use command-line input as a stylesheet parameter.
*/
public class UseStylesheetParam
{
public static void main(String[] args)
throws ProcessorException, ProcessorFactoryException,
TransformException, SAXException, IOException
{
if(args.length != 1)
{
System.err.println("Please pass one string to this program");
return;
}
// Get the parameter value from the command line.
String paramValue = args[0];
Processor processor = Processor.newInstance("xslt");
Templates templates = processor.process(new InputSource("foo.xsl"));
Transformer transformer = templates.newTransformer();
// Set the parameter. I can't get non-null namespaces to work!!
transformer.setParameter("param1", /* parameter name */
null, /*
parameter namespace -- usually null */
paramValue /*
parameter value */ );
transformer.transform(new InputSource("foo.xml"), new Result(System.out));
}
}