XSLTc


XSLTc was developed by Jacek Ambroziak, at Sun Microsystems, for high performance and repeated transformations. It was released to the Apache project and is packaged with the JAXP reference implementation.

Most implementations read the style sheet sequentially using SAX, create an internal object representation from it, and use that to transform the source tree to the result tree. As Figure 9.9 shows, XSLTc takes the orginal XSL file and compiles it into Java bytecodes, called translets. The translet class, representing an optimized internal DOM (not the W3C DOM), along with the internal caching mechanism of XSLTc, increases application performance.

click to expand
Figure 9.9: XSLTc architecture

All the implementation details of XSLTc are hidden from the application, because of JAXP's architecture. XSLTc is treated as another implementation of the transformer underneath the API. The code to use XSLTc remains the same as earlier; only the factory implementation class, represented by the system property javax.xml.transform.TransformerFactory, changes from the default org.apache

                .xalan.processor.TransformerFactoryImpl to org.apache.xalan.xsltc.trax                .TransformerFactoryImpl.              String xml_1 = "pitransform.xml";              String xml_2 = "saxexample2.xml";              String xsl = "fluteadmin.xsl";              System.setProperty("javax.xml.transform.TransformerFactory",                                 "org.apache.xalan.xsltc.trax.TransformerFactoryImpl"); // instantiate the factory              TransformerFactory factory = TransformerFactory.newInstance(); // obtain a template from the factory // results in the stylsheet being compiled into a translet              Templates template = factory.newTemplates(new StreamSource(xsl));              Transformer transformer = template.newTransformer(); // use the transformer to transform the source to a result              transformer.transform(new StreamSource(new File(xml_1)),                                                     new StreamResult(System.out));              transformer.transform(new StreamSource(new File(xml_2)),                                                     new StreamResult(System.out)); 

When using XSLTc in a production application, the first part of the code that results in compilation would typically be handled at application startup, with only the reference to the Templates object passed around (recall that it is thread safe). XSLTc also comes with a Java API that can be used to invoke the code directly and to physically produce a class file from a style sheet. However, using that would make the code nonportable to other implementations.




Java Web Services Architecture
Java Web Services Architecture (The Morgan Kaufmann Series in Data Management Systems)
ISBN: 1558609008
EAN: 2147483647
Year: 2005
Pages: 210

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net