Using Ant With XSLT 2.0 and Saxon

You will first have to download the Saxon libraries. You can find them at the SourceForge Saxon Web Page I put the files in my C:/Apps/saxon8 folder

I then add the following to a properties file:

-- content of file --

# used to make sure Saxon gets the right XSLT 2.0 processor

-- end of file --

Here is an excerpt from my build file

-- contents of build.xml --

<!-- load the local properties file -->
<property file=""/>

<!-- a sample task that demonstrates the use of Saxon 8 -->
<target name="XSL using Saxon"
        description="Demonstration of XSL using Saxon">
      processor="${processor}" >

The following is an handy transform for printing the XSLT 2.0 and system related variables -- MyTransform.xsl --

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="" version="1.0">
   <xsl:output method="html"/>
      <xsl:template match="/">
               <title>Print XSLT Related Environment Variables</title>
                   <li><b>Version: </b><xsl:value-of select="system-property('xsl:version')"/>
                   <li><b>Vendor: </b><xsl:value-of select="system-property('xsl:vendor')"/>
                   <li><b>Vendor URL: </b><xsl:value-of select="system-property('xsl:vendor-url')"/>
                   <li><b>Java Version: </b><xsl:value-of select="system-property('java.version')"/>
                   <li><b>OS Name: </b><xsl:value-of select="system-property('')"/>
                   <li><b>File Seperator: </b><xsl:value-of select="system-property('file.separator')"/>

This should display something like the following:

-- output of MyOutput.htm --

To use this just create an empty XML input file with a valid root: -- MyInput.xml --

<?xml version="1.0" encoding="UTF-8"?>

Or once you have downloaded saxon8.jar, simply call Ant with -lib path/to/saxon8.jar on the command line, and use <xslt> as usual. Since Saxon implements the TraX API, and is now first on Ant's classpath, <xslt> will automatically pick it up. Wrap the appropriate -lib option in a custom startup script, or use an ANT_OPTS EnvironmentVariable to avoid having to type it all the time. --DD

UsingAntWithXSLT20AndSaxon (last edited 2009-09-20 22:07:53 by localhost)