Mark Wilson I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :
03/24/2008
Times viewed :
685
Xalan: XSLTC
XSLTC provides
API to compile a stylesheet to generate compiled version of stylesheet(called
translets) and processor to apply compiled version of stylesheet(translets) on
xml to produce output(.html/.xml/.wml).
Flow of XSLTC
In the above
diagram, XSLTC provides compiler which compiles stylesheets and produces
translets. XSLTC also provides runtime processor which applies translets on xml
document and transforms into desired output.
Note: To compile
and run translets, you should have JRE 1.2 and above.
Setting upon
your classpath
Previously XSLTC
classes are coming with xsltc.jar so other required jar file to be added to
system classpath. If you are running with original XSLTC, then ensure that all
required jar files also added in your system classpath.
Now,
a single xalan.jar contains the code for both Xalan-Java processors. You can
use the JAXP javax.xml.transform.TransformerFactory
property to select which processor to use: the Interpretive or the Compiling
processor.
Compiling
Translets from Commandline
XSLT Compiler is
a java based utility, that compiles stylesheets and produces a lightweight and
portable Java byte codes called translets.
Note: Ensure that
your translet file is in your classpath.
Use XSLTC with
JAXP1.2
To use the JAXP 1.2
API to perform transformations with translets do the following:
Set the javax.xml.transform.TransformerFactory system property as indicated above.
Instantiate a TransformerFactory.
Instantiate a Transformer object either directly from the TransformerFactory or through a Templates object. A Transformer is a processed instance of a
stylesheet (a translet) that can be used to perform a transformation. See
below for more information on when you should use a Templates object.
Perform the transformation, using a StreamSource
object for the XML input and a StreamResult object to hold the
transformation output.
Both
a Templates object and a Tranformer
object are processed representations of a stylesheet, but you cannot use a Templates object to perform transformations. Instead, you can use a Templates object to create new Transformer instances, without having to reprocess the stylesheet each
time. You can use a TransformerFactory to
generate a Templates object or a Transformer object directly. You can use a Transformer more than once, but you cannot use it concurrently on more
than one thread. If you need to use the same stylesheet to perform
transformations on more than one thread at the same time, use a
Templates object and create as many Transformer objects as you require.
XSLTC also
defines a set of attributes that you can set on the TransformerFactory in order
to save and subsequently use those translets by way of the JAXP Transform API -
without having to recompile the stylesheet each time.