Ant + Saxon9b + multiple files

Here should go questions about transforming XML with XSLT and FOP.
kleb
Posts: 4
Joined: Fri Jan 18, 2008 10:11 pm

Ant + Saxon9b + multiple files

Post by kleb »

Oxygen supports applying a XSL transform to a directory of files, but in doing so, it invokes a separate instance of the transform engine for each file, adding a large amount of overhead.

In contacting Oxygen tech support about this, I was recommended to use Ant as a solution. I am posting the results here in the hope that it will be helpful to someone in the same situation (make changes to xsl, run on all files and check output to see if output is as expected).

First, Ant needs to be installed: http://ant.apache.org/manual/install.html#getting

Then an Ant build file needs to be created in the project directory. This is the one I used.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<project default="cleanup">
<target name="cleanup">
<xslt
basedir="${sourcefiles}"
destdir="${destdir}"
extension="htm"
includes="*.htm"
style="${stylesheet}"
classpath="${oxy_dir}\lib\saxon9.jar"
></xslt>
</target>
</project>
Note: the extension attribute specifies the output file extension.

Then, create a custom External Tool in Oxygen: Tools > External Tools > Preferences > New
Insert this text into the command line field:

ant.bat -f ${pd}\<name-of-ant-buildfile> -Dsourcefiles=${cfd} -Ddestdir="<destination-directory>" -Dstylesheet=${pd}\<stylesheet-to-use>.xsl -Doxy_dir=${oxygenInstallDir}

To do a batch transformation, open a file in the source directory and execute the custom External Tool command that you created.

Speed difference for transforming 278 files with Saxon 9B:
Oxygen batch transform: 1 minute 30 seconds
Ant: 4 seconds

And Oxygen has autocomplete for Ant files. Just make a new xml file with <project> as the root element.

-Caleb
kleb
Posts: 4
Joined: Fri Jan 18, 2008 10:11 pm

files existing

Post by kleb »

I just noticed that if the transformed files already exist, the Ant file will not overwrite them. You could add a force="yes" attribute to the <xslt> element to override this behavior.

-Caleb
kleb
Posts: 4
Joined: Fri Jan 18, 2008 10:11 pm

Post by kleb »

Note: the extension attribute of <xslt> should be ".htm" not "htm"
Post Reply