How to execute XSLT 2.0 with ant?

paulgreg picture paulgreg · May 28, 2009 · Viewed 16.5k times · Source

I'm trying to run an XSLT transformation from an ant file.

I'm using a XSLT 2.0 stylesheet with a saxon 9 parser (supporting XSLT 2.0).

The problem is that it seems that ant is always calling an XSLT 1.0 parser.

Here's my ant file :

<xslt style="stylesheet.xslt"
   basedir="core/"    
   extension=".xml"
   destdir="core/"
   classpath="D:\\DevTools\\saxon\\bin\\saxon9.jar">
</xslt>

If I call it directly (without ant), it's working.

Any idea ?

Answer

jelovirt picture jelovirt · May 31, 2009

The problem is that while Saxon is added to the classpath, the default JAXP mechanism to determine which TransformerFactory is used and it will use the default that is Xalan. You either need to:

  • Set javax.xml.transform.TransformerFactory system variable to net.sf.saxon.TransformerFactoryImpl,
  • Add saxon9.jar to the CLASSPATH system variable, or
  • Use <factory name="net.sf.saxon.TransformerFactoryImpl"/> inside the xslt element