Abbey Workshop | ||||||||||
Well I have been wondering for some time how to make Saxon your Ant XSLT processor instead of Xalan. Recently, troubleshooting an issue allowed me some deeper exploration. It turns out that making Saxon your XSLT processor is pretty easy. Basically all you need is a test XSLT 2.0 file to verify that your are using Saxon and a minor tweak to the xslt task in Ant.
First, take a look at the sample xslt 2.0 code.
Download source for: xslt2-test.xsl
This small snippet of XSLT 2.0 code calls the XPath 2.0 currentdate() function. If an XSLT 2.0 processor is called, you get an output XML document with the current date in it. If an XSLT 1.0 processor like Xalan is called, the processor chokes and you get an error message like this.
Buildfile: build.xml
xslt2:
[xslt] Processing /home/howto/xslt/ant-saxon/test.xml to
/home/howto/xslt/ant-saxon/xslt2-test.xml
[xslt] Loading stylesheet
/home/howto/xslt/ant-saxon/xslt2-test.xsl
[xslt] : Error! Error checking type of the expression
'funcall(current-date, [])'.
[xslt] : Fatal Error! Could not compile stylesheet
[xslt] Failed to process /home/howto/xslt/ant-saxon/test.xml
BUILD FAILED
/home/howto/xslt/ant-saxon/build.xml:5: Fatal error during
transformation
Total time: 1 second
Since there is no currentdate() XPath function in an XSLT 1.0 processor, it is a pretty easy way to check.
Now for the Ant code. Here is the modified build file to make Ant use Saxon.
Download source for: build.xml
You mean you only have to put the path to the saxon8.jar file in the classpath? That's it?
That's it boys and girls, that is all it takes. That small change should allow to easily plug-in Saxon into your Ant XSLT build scripts. Have fun.
Copyright © Abbey Workshop 2006