[xsl] TransformerImpl and LexicalHandler

Subject: [xsl] TransformerImpl and LexicalHandler
From: Naeim Semsarilar <naeims@xxxxxxxxx>
Date: Sun, 10 Aug 2003 09:29:02 -0700 (PDT)
Hi,

I'm using xalan-j_2_5_1.

I'm doing a simple xsl transformation in java. my
source is a StreamSource and my result is a SAXResult.
Below is my code:

void outputFilter(Reader in, Object desc, Writer out)
{
    try {
      TransformerFactory tFactory =
TransformerFactory.newInstance();
      StreamSource xmlSrc = new StreamSource( new
BufferedReader(in) );
      xmlSrc.setSystemId( (File) desc );
      StreamSource xslSrc = new StreamSource( new
FileReader("p2c.xsl") );
      Transformer transformer =
tFactory.newTransformer(xslSrc);
      BufferedWriter bw = new BufferedWriter(out);
      BetterXMLWriter xw = new BetterXMLWriter(bw);
      xw.setIndentStep(2);

      SAXResult sr = new SAXResult();
      sr.setHandler(xw);
      sr.setLexicalHandler(xw);
      sr.setSystemId("oxreq");

      transformer.transform(xmlSrc, sr);
      bw.close();
    }
    catch(Exception exp) {exp.printStackTrace();}
}


BetterXMLWriter is a specialized 
com.megginson.sax.DataWriter that implements
LexicalHandler and writes DOCTYPE definitions and
comments to the outputstream.

I noticed that no callbacks to the LexicalHandler are
made if
org.apache.xalan.processor.TransformerFactoryImpl was
instantiated as my TransformerFactory (which then
instantiates
org.apache.xalan.transformer.TransformerImpl as the
Transformer). 

After some trial & error attempts, I could put my
LexicalHandler back in the system by using
org.apache.xalan.xsltc.trax.TransformerFactoryImpl as
my TransformerFactory (by setting a system property)
and that would instantiate
org.apache.xalan.xsltc.trax.TransformerImpl for the
Transformer.

I was happy, but then I tried using extension
functions with the latter Transformer and got the
following error:

ERROR:  'The first argument to the non-static Java
function 'parse' is not a valid object reference.'
FATAL ERROR:  'Could not compile stylesheet'
javax.xml.transform.TransformerConfigurationException:
Could not compile stylesheet
	at
org.apache.xalan.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:740)
	at
org.apache.xalan.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:518)


The same extension function in question simply passes
a NodeSet to a static java method (as a NodeList) and
excepts a String. And it works with the former
Transformer (the one which LexicalHandler didn't work
with).

Does this sound familiar to anyone? I need both the
LexicalHandler functionality and extension functions
but seems like these to Transformers don't support
both.

Thanks for any help in advance.

-Naeim


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread