Ant - Build file to run xsltproc

By xngo on June 29, 2019

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
Description: Write a target to run xsltproc from Ant
-->
<project basedir="." default="run_xsltproc" name="run_xsltproc">
 
  <!-- Note: I explicitly use the --output option provided by xsltproc
              so that in case of error, it will show in the eclipse console. 
  -->
  <target name="run_xsltproc">
    <exec executable="xsltproc.exe" failonerror="true">
      <arg value="--xinclude"/>
      <arg value="--output" />
      <arg value="your_xml_output_file.html" />
      <arg value="your_xsl.xsl"/>
      <arg value="your_xml_input_file.xml"/>
    </exec>
  </target>
 
</project>

In case where you can't run xsltproc.exe because of issue with MSVCRT.dll and that you need to resolve XInclude, then use xmllint.exe to resolve XInclude and Saxon to process the transformation. Here is an example:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>              
  <!-- Use xmllint & Saxon because there is an issue with MSVCRT.dll for xsltproc -->
  <exec executable="xmllint" failonerror="true">
    <arg value="--xinclude"/>
    <arg value="your_xml_input_file.xml"/>
    <arg value="--output" />
    <arg value="lint.tmp.xml" />
  </exec>
 
  <java jar="lib/saxon/saxon.jar"
    output="your_xml_output_file.html"
    fork="true">
 
    <arg value="lint.tmp.xml"/>
    <arg value="your_xsl.xsl"/>
  </java>
</project>

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.