tags:

views:

1423

answers:

3

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 ?

+2  A: 

This tutorial seems to give step by step instructions on how to do what you are asking:

http://www.abbeyworkshop.com/howto/xslt/ant-saxon/index.html

From that it appears you are doing the correct thing. Are you sure you need the double back slashes?

Update: The xslt ant documentation mentions the 'factory' property which may help you get closer:

http://ant.apache.org/manual/CoreTasks/style.html

samjudson
On windows, I think I need.
paulgreg
updated - possibly use the 'factory' attribute.
samjudson
+4  A: 

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
jelovirt
A: 

Create a taskdef from the Saxon AntTransform class:

  <taskdef name="saxon-xslt" classname="net.sf.saxon.ant.AntTransform" classpath="${basedir}/lib/saxon/saxon9.jar;${basedir}/lib/saxon/saxon9-ant.jar"/>

   <saxon-xslt
     in="${source.xml}"
     out="${out.dir}/${output.xml}"
     style="${basedir}/${stylesheet.xsl}"
     force="true">
   </saxon-xslt>
Mads Hansen