The JavaTM Web Services Tutorial
Home
TOC
Index
PREV TOP NEXT
Divider

Choosing the Transformation Engine

This section provides the information you need to help you choose between the interpreting transformer (Xalan) and the compiling transformer (XSLTC).

Performance Considerations

For a single-pass translation, the interpreting transformer (Xalan) tends to be slightly faster than the compiling transformer (XSLTC), because it isn't generating and saving the byte-codes in the small Java classes that are run as translets.

But when a transformation will be used multiple times, it makes sense to use the XSLTC transformation engine because, in such settings, XSLTC is the clear winner when it comes to memory requirements and performance.

An XSLTC translet tends to be small, because it implements only those translations that the stylesheet actually performs. And it tends to be fast, both because it is smaller and because the lexical handling necessary to interpret the stylesheet has already been performed. Finally, translets tends to load faster and generally be more sparing of system resources, due to their small size.

For example, a servlet that will be running for long periods of time tends to benefit by using XSLTC. Similarly, a transformation that is run from the command line tends to run faster when XSLTC is used. You'll see more about that process in Transforming from the Command Line.

In addition to making it possible to cache translets, XSLTC provides a number of other options to help you maximize performance:


Note: There are also rules for things to do and things to avoid when designing your stylesheets, in order to get maximum performance with XSLT. For more information on that subject, see http://xml.apache.org/xalan-j/xsltc/xsltc_performance.html.

Functionality Considerations

While XSLTC tends to be a higher performance choice for many applications, Xalan has some advantages in functionality. Among those advantages are the support for the standard query language, SQL.

Making Your Choice

Whether you get the Xalan or XSLTC transformation engine is determined by factory configuration settings. By default, the JAXP factory creates a Xalan transformer. To get an XSLTC transformer, the preferred method is to set the TransformationFactory system property like this:

javax.xml.transform.TransformerFactory=
    org.apache.xalan.xsltc.trax.TransformerFactoryImpl
 

At times, though, it is not possible to set a system property -- for example, because the application is a servlet, and changing the system property would affect other servlets running in the same container. In that case, you can instantiate the XSLTC transformation engine directly, with a command like this:

new org.apache.xalan.xsltc.trax.TransformerFactoryImpl(..)
 

You could also pass the factory value to the application, and use the ClassLoader to create an instance of it at runtime.


Note: To explicitly specify the Xalan transformer, you would use the value org.apache.xalan.processor.TransformerFactoryImpl, instead of org.apache.xalan.xsltc.trax.TransformerFactoryImpl.

There is also a "smart transformer" that uses the Xalan transform engine when you generate Transformer objects, and the XSLTC transform engine when you generate intermediate Templates objects. To get an instance of the smart transformer, use the value org.apache.xalan.xsltc.trax.SmartTransformerImpl either to set the transformer factory system property or use that class to instantiate a parser directly.

Divider
Home
TOC
Index
PREV TOP NEXT
Divider

This tutorial contains information on the 1.0 version of the Java Web Services Developer Pack.

All of the material in The Java Web Services Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.