[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

TransformerImpl and LexicalHandler

Subject: TransformerImpl and LexicalHandler
From: Naeim Semsarilar <naeims@xxxxxxxxx>
Date: Sun, 10 Aug 2003 09:29:02 -0700 (PDT)
com.megginson.sax.datawriter
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.