dleslie 00/10/20 05:51:11
Added: java/samples/UseStylesheetPI foo.xsl fooX.xml
UseStylesheetPI.java
Log:
Added TraceListener and stylesheet PI samples.
Revision Changes Path
1.1 xml-xalan/java/samples/UseStylesheetPI/foo.xsl
Index: foo.xsl
===================================================================
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="doc">
<out><xsl:value-of select="."/></out>
</xsl:template>
</xsl:stylesheet>
1.1 xml-xalan/java/samples/UseStylesheetPI/fooX.xml
Index: fooX.xml
===================================================================
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="foo.xsl"?>
<doc>Hello</doc>
1.1
xml-xalan/java/samples/UseStylesheetPI/UseStylesheetPI.java
Index: UseStylesheetPI.java
===================================================================
// Imported TraX classes
import org.apache.trax.Processor;
import org.apache.trax.Templates;
import org.apache.trax.Transformer;
import org.apache.trax.Result;
import org.apache.trax.ProcessorException;
import org.apache.trax.ProcessorFactoryException;
import org.apache.trax.TransformException;
// Imported SAX classes
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
// Imported java.io classes
import java.io.FileOutputStream;
import java.io.IOException;
public class UseStylesheetPI
{
public static void main(String[] args)
throws ProcessorException, ProcessorFactoryException,
TransformException, SAXException, IOException
{
String media= null , title = null, charset = null;
try
{
Processor processor = Processor.newInstance("xslt");
InputSource[] stylesheet = processor.getAssociatedStylesheets
(new InputSource("fooX.xml"),media, title, charset);
Templates templates = processor.processMultiple(stylesheet);
Transformer transformer = templates.newTransformer();
transformer.transform(new InputSource("fooX.xml"), new
Result(new java.io.FileOutputStream("foo.out")));
}
catch (SAXException se)
{
System.err.println(se.toString());
se.printStackTrace();
Exception e = se.getException();
if(e!=null)
{
e.printStackTrace();
}
}
catch (Exception e)
{
System.err.println(e.toString());
e.printStackTrace();}
}
}