You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Herman Verhagen <h....@publitec.vnu.com> on 2001/02/02 09:18:27 UTC

Can't parse

Hi , 
Herewith I would like to ask you something about Apachae Xalan Java 2 XSLT
processing.

The command line command:
	java -cp xerces.jar;xalan.jar org.apache.xalan.xslt.Process -IN
xmlFile -XSL xslFile -OUT outFile
Processes the following line in xmlFile correctly:
	<xsl:include href="Variables.xsl"/>

So far, so good. However, in our project there's a need to do the XSL
parsing in internal memory.
In order to do so, I wrote some code (see below) based on example code on
the xalan site.
This code doesn't process an xslFile with an <xsl:include
href="Variables.xsl"/> correctly (NullPointerException is raised).
I tried to use both DOM parsing and SAX 2 parsing.

Questions:
Is it possible to get the source code of class
org.apache.xalan.xslt.Process?
Or can you tell me what I'm doing wrong (e.g. which statement is missing in
the code below)?

Thanks in advance,

Herman Verhagen


P.S. relevant substract of my code (detailed exception handling is left out,
just showing the sequence of statements):

    static public String saxTransform(String xslSystemId, String xmlString)
    {
       String result = null;
       org.apache.trax.Processor xsltProcessor = null;
       org.apache.trax.Transformer xslTransformer = null;
       org.xml.sax.ContentHandler contentHandler = null;
       org.apache.trax.Templates stylesheet = null;
       java.io.ByteArrayOutputStream outputStream = null;
       org.apache.trax.Result outputResult = null;
	   org.xml.sax.XMLReader xmlReader = null;
	   org.apache.serialize.Serializer xmlSerializer = null;

      try {
         xsltProcessor = org.apache.trax.Processor.newInstance("xslt");
         xmlReader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
         xmlSerializer =
org.apache.serialize.SerializerFactory.getSerializer(
                            org.apache.serialize.Method.XML);
         outputStream = new java.io.ByteArrayOutputStream(1024);
         outputResult = new org.apache.trax.Result(outputStream);
         
         stylesheet = xsltProcessor.process(
         				new
org.xml.sax.InputSource(xslSystemId)  );
         xslTransformer = stylesheet.newTransformer();
         contentHandler = xslTransformer.getInputContentHandler();
    	 xmlReader.setContentHandler(contentHandler);

         if (contentHandler instanceof org.xml.sax.ext.LexicalHandler) 
	
xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler",
                               contentHandler );
	     else
	
xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler",
null);
			
         xmlSerializer.setOutputStream(outputStream);

         xslTransformer.setContentHandler(xmlSerializer.asContentHandler());

         xmlReader.parse(new org.xml.sax.InputSource(
                              new java.io.StringReader(xmlString) ) );

         result = outputStream.toString();
       } catch(Exception e) {
          e.printStackTrace(System.err);
       }
          
       return result;
    }