XSLTc was developed by Jacek Ambroziak, at Oracle, 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 Screenshot 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 app performance.

Java Click To expand
Screenshot: XSLTc architecture

All the implementation details of XSLTc are hidden from the app, 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
 String xml_1 = "pitransform.xml";
 String xml_2 = "saxexample2.xml";
 String xsl = "fluteadmin.xsl";
// 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 app, the first part of the code that results in compilation would typically be handled at app 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.