Processing topics with XSLT in preprocess

You can add an Ant target to the end of the pre-processing pipeline that transforms all topics. This is useful if you want to modify topics before transtype-specific processing, for example to modularize the code or reuse the same processing in multiple transformation types.


  1. Create a plug-in descriptor file plugin.xml that imports a new Ant buildfile build.xml and adds an Ant target after pre-processing.
    <?xml version="1.0" encoding="utf-8"?>
    <?xml-model href="" type="application/relax-ng-compact-syntax"?>
    <plugin id="plugin-id">
      <feature extension="ant.import" file="build.xml"/>
      <feature extension="" value="uniform-decimals"/>
  2. Create an Ant buildfile build.xml with a target to process all DITA topics in the temporary directory.
    <?xml version="1.0" encoding="utf-8"?>
      <target name="uniform-decimals">
        <pipeline taskname="xslt">
          <xslt basedir="${dita.temp.dir}"
            <ditafileset format="dita" processingRole="normal"/>
  3. Create an XSLT stylesheet filter.xsl to filter topic content.
    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="2.0" xmlns:xsl=""
      xmlns:xs="" exclude-result-prefixes="xs">
      <!-- Format keywords with a decimal number with at least two decimal points -->
      <xsl:template match="*[contains(@class, ' topic/keyword ')]">
          <xsl:apply-templates select="@*"/>
          <xsl:variable name="num" select="number(.)" as="xs:double"/>
            <xsl:when test="$num = $num and contains(., '.')">
              <xsl:attribute name="orig" select="."/>
              <xsl:value-of select="format-number($num, '0.00#')"/>
              <xsl:apply-templates select="node()"/>
      <!-- Identity template -->
      <xsl:template match="@* | node()">
          <xsl:apply-templates select="@* | node()"/>
  4. Use the dita install subcommand to install the plug-in.
    For more information, see Installing plug-ins.


The filter.xsl stylesheet will transform every DITA topic after pre-processing.