You can
just add the -XSLTC option to your
existing option list so that it will do the same thing as before,
but using XSLTC.
Here is a
simple example on how to use XSLTC:
>
java
org.apache.xalan.xslt.Process -in test.xml -xsl test.xsl
-xsltc
XSLTC
compiles the stylesheet on the fly and uses the bytecode in memory
to transform the input xml. No translet class is generated in this
simple usage pattern.
If you
want to generate translet classes from the stylesheet, you can use
the -XO
option:
>
java
org.apache.xalan.xslt.Process -in test.xml -xsl test.xsl -xsltc
-xo
This
example still uses the stylesheet for transformation, but it also
generates the translet class "test.class".
You can
use the -XJ,
-XP or -XD options to further
customize the translet generation behavior. Translets will be
generated if any of the options -XO, -XJ or -XT is used.
>
java
org.apache.xalan.xslt.Process -in test.xml -xsl test.xsl -xsltc -xo
newTranslet -xd temp -xp org.apache.test -xj
translets.jar
The above
command line uses the xsl for transformation. It also generates
translet classes in the name of newTranslet , using a
package prefix of org.apache.test , and
packages the translets into the jar file translets.jar under the
temp
directory.
All of the
examples above use the stylesheet to do the transformation. If the
translets are already generated, you can use the -XT option to specify that
you want to use the existing translets for transformation. The
-XT option has
a makefile like feature in that it will compare the timestamps of
the translet and the stylesheet. If the translet is newer, it is
used for the transformation, otherwise the stylesheet is used and
the translet is regenerated.
The
translet is loaded from the specified destination directory or the
current directory, using the specified translet name or the xsl
base name, depending on whether the -XD or -XO option is used. The
options -XO, -XD,
-XP and -XJ can be used with the
-XT option to
tell XSLTC how to find the translet classes. The translets are
directly read in as bytecode. You do not need to add the translet
directory or the jar file to your classpath.
Example:
>
java
org.apache.xalan.xslt.Process -in test.xml -xsl test.xsl -xsltc -xt
-xj translets.jar -xd temp
This
command line will search for the translet test.class inside the jar
file temp/translets.jar . If it
is found and newer than test.xsl, it is used for the
transformation; otherwise the xsl is used and the translet is
generated and packaged in the same jar.
Here is
how the makefile feature for the -XT option
works:
- If the
xsl does not exist, use the translet
- If the
translet does not exist, use the xsl and generate a new
translet
- If both
exist and the translet is newer, use the translet for
transformation
- If both
exist and the xsl is newer, use the xsl for transformation and
regenerate the translet
|