XML technologies / DITA / DITA Open Toolkit / ANT

(Excerpt from “DITA – Der neue Standard für Technische Dokumentation” by Johannes Hentrich)

With ANT (Another Neat Tool), applications can be built from individual components. The Unix command make uses a similar concept to build installable software from existing source code, libraries and other files. In the DITA Open Toolkit, ANT produces output formats from DITA XML files, maps, XSLT stylesheets and other stylesheets.

ANT is controlled through build files, which are XML files. The element <target> and the element <property> are the two most important elements in an ANT build file.

The element <target> defines which output format to generate.

The element <property> defines the properties or conditions for generating the output. The element <property> named transtype specifies the transformation type, which determines the output format to produce.

The DITA Open Toolkit supplies numerous sample ANT build files, so you do not need to learn their syntax in detail.

The DITA Open Toolkit distinguishes two kinds of ANT build files:

The next two sections show how to adapt the sample ANT build files to your requirements for producing XHTML, that is, transformation type xhtml, and PDF, that is, transformation type pdf or pdf2. Sample ANT build files are also available for the following transformation types:

The sample build files for these transformation types are adapted in the same way as shown in the next two sections.

ANT build file for XHTML production

The ANT build file uses the file template_xhtml.xml from the toolkit’s ant directory as a template.

The file template_xhtml.xml has the following content:

<?xml version="1.0" encoding="UTF-8"?>
<project name="@PROJECT.NAME@_xhtml" default="@DELIVERABLE.NAME@2xhtml" basedir=".">
  <property name="dita.dir" value="${basedir}${file.separator}.."/>
  <import file="${dita.dir}${file.separator}integrator.xml"/>
  <target name="@DELIVERABLE.NAME@2xhtml" depends="integrate">    
    <ant antfile="${dita.dir}${file.separator}build.xml" target="init">
      <property name="args.input" value="@DITA.INPUT@">
      <property name="output.dir" value="@OUTPUT.DIR@"/>
      <property name="transtype" value="xhtml"/>
    </ant>
  </target>
</project>

To adapt the file template.xhtml for your project, replace the placeholders as follows:

  • @PROJECT.NAME@_xhtml: enter the name you give the ANT build file, without its extension, for example mein_projekt.

  • @DELIVERABLE.NAME@2xhtml: you can freely choose the name of the output to produce.

  • @DITA.INPUT@: enter the path to the directory containing the map to process. Use ${file.separator} as the separator between directory and file names.

  • @OUTPUT.DIR@: enter the directory where the generated XHTML files should be saved. Use ${file.separator} as the separator between directory and file names.

In <property name="dita.dir" value="${basedir}${file.separator}.."/> the path to the DITA Open Toolkit is specified. ${basedir} is the toolkit installation directory. Since the file template_xhtml.xml is in the toolkit’s ant directory, the value points one directory level up. Change this value according to where you store your ANT build file.

With the full DITA Open Toolkit package, start XHTML production as follows:

  1. Start the startcmd.bat-Datei.

  2. Change to the directory containing your ANT build file.

  3. Enter ant -f mein_projekt.xml .

  4. Confirm your entry.

After successful processing, the message BUILD SUCCESSFUL is displayed.

ANT build file for PDF production

The ANT build file for PDF production uses the template_pdf.xml file from the toolkit’s ant directory as a template.

<?xml version="1.0" encoding="UTF-8"?>
<project name="@PROJECT.NAME@_pdf" default="@DELIVERABLE.NAME@2pdf" basedir=".">
  <property name="dita.dir" value="${basedir}${file.separator}.."/>
  <import file="${dita.dir}${file.separator}integrator.xml"/>
  <target name="@DELIVERABLE.NAME@2pdf" depends="integrate">
    <ant antfile="${dita.dir}${file.separator}build.xml" target="init">
      <property name="args.input" value="@DITA.INPUT@"/>
      <property name="output.dir" value="@OUTPUT.DIR@"/>
      <property name="transtype" value="pdf"/>
    </ant>
  </target>
</project>

To adapt the file template_pdf.xml for your project, replace the placeholders as follows:

  • @PROJECT.NAME@_xhtml: enter the name you give the ANT build file, without its extension, for example mein_projekt.

  • @DELIVERABLE.NAME@2xhtml: you can freely choose the name of the output to produce.

  • @DITA.INPUT@: enter the path to the directory containing the map to process. Use ${file.separator} as the separator between directory and file names.

  • @OUTPUT.DIR@: enter the directory where the generated XHTML files should be saved. Use ${file.separator} as the separator between directory and file names.

In <property name="dita.dir" value="${basedir}${file.separator}.."/> the path to the DITA Open Toolkit is specified. ${basedir} is the toolkit installation directory. Since the file template_xhtml.xml is in the toolkit’s ant directory, the value points one directory level up. Change this value according to where you store your ANT build file.

The setting <property name="transtype" value="pdf"/> specifies that PDFs are generated using the standard mechanism, that is, the DITA Open Toolkit’s XSLT stylesheets and Apache FOP.

If you set the transformation type to pdf2, that is, <property name="transtype" value="pdf2"/>, PDFs are generated through the FO plugin, provided it is installed.

With the full DITA Open Toolkit package, start PDF production as follows:

  1. Start the startcmd.bat-Datei.

  2. Change to the directory containing your ANT build file.

  3. Enter ant -f mein_projekt.xml .

  4. Confirm your entry.

After successful processing, the message BUILD SUCCESSFUL is displayed.

  

 

 

 

back to top