Apache Ant/XQuery


You want to transform an XML document with XQuery using an ant task.


We will use the Saxon library to demonstrate this.


  1. Download the Saxon library from Sourceforge
  2. Download a sample XQuery from the samples (for example tour.xq from the samples area)
  3. Copy the Saxon jar file into your project. In the example below just a single jar file is copied into the location saxonhe9-2-0-6j/saxon9he.jar

Sample Ant TargetEdit

This sample uses the java task to run an XQuery program using the Saxon Java library. In the example below the XQuery tour.xq is executed and the output is copied into the file output.html.

Note that the starting point is set by passing the arg as a parameter to the XQuery.

<target name="run-saxon-xquery">
    <java classname="net.sf.saxon.Query" output="output.html">
             <arg value="tour.xq"/>
                <pathelement location="saxonhe9-2-0-6j/saxon9he.jar"/>
             <arg value="start=e5"/> 	
    <!-- On Windows, this will open FireFox after the Transform is done -->
    <exec command="C:\Program Files\Mozilla Firefox\firefox.exe