Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute XSLT 2.0 with ant?

Tags:

xslt

ant

saxon

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 ?

like image 491
paulgreg Avatar asked May 28 '09 07:05

paulgreg


People also ask

Which of the below Apache Ant task performs XML transformations?

Apache Ant has a task called <xslt> (or its synonym <style>) that performs an XML transform on a file or group of files.

Which of the following tasks can be performed with XSLT?

The XSLT processor can perform the following tasks: Reads one or more XSLT stylesheets. The processor can apply multiple stylesheets to a single XML input document and generate different results. Reads one or more input XML documents.


1 Answers

EDIT: Dr. Michael Kay has pointed out that the AntTransform is no longer supported, nor recommended.

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>


I have begun using the standard <xslt> task with the saxon jar specified in a <classpath>, but had been running into performance issues. It seemed to "hang" for a bit when the task was called. I have found that adding processor="trax" and specifying <factory name="net.sf.saxon.TransformerFactoryImpl"/> helps it run much faster.

 <xslt in="${source.xml}"
       out="${out.dir}/${output.xml}"
       style="${basedir}/${stylesheet.xsl}"
       processor="trax">
       <factory name="net.sf.saxon.TransformerFactoryImpl"/>
       <classpath refid="saxon-classpath" />
 </xslt>  
like image 89
Mads Hansen Avatar answered Sep 24 '22 02:09

Mads Hansen