ANT target for applying an XSLT stylesheet to a directory of XML files

Viewed 30

I'm copying a series of XML files to a directory and I want to apply a stylesheet to all the XML files in this directory (D:\workspace\Filtered) but I haven't been able to figure out the syntax for the srcfile and targetfile.

    <fileset id="xmlfileset" dir="D:\workspace">
      <include name="*.xml" />
      <include name="*.XML" />
      <exclude name="build_*" />
    </fileset>
    
    <target name="Filtering">
    
    <mkdir dir="D:\workspace\Filtered"/>
    <copy todir="D:\workspace\Filtered">
      <fileset refid="xmlfileset"/>
    </copy>
    <apply executable="msxsl.exe">

      <srcfile/>
      <!-- what goes here -->

      <arg value="D:\workspace\sample.xslt"/>
      <arg value="-xe"/>
      <arg value="-xw"/>
      <arg value="-o"/>

      <targetfile />
      <!-- and  here -->

    </apply>
  </target>
1 Answers

You probably need to add the fileset to tell it which files to run the command for, and perhaps a file name mapper to create a file with a new name (perhaps a new extension).

The srcfile and targetfile elements are filled with those file names for each run of the executable.

Both should go within the apply element. Something like:

<apply executable="msxsl.exe">
  <fileset refid="xmlfileset"/>
  <globmapper from="*.[xX][mM][lL]" to="*.NewExtension"/>

  <srcfile/>

  <arg value="D:\workspace\sample.xslt"/>
  <arg value="-xe"/>
  <arg value="-xw"/>
  <arg value="-o"/>

  <targetfile />
</apply>
Related