XML technologies / DITA / DITA Open Toolkit / Idiom FO plugin

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

Originally, the DITA Open Toolkit had several weaknesses in PDF generation. This prompted Chris Wong of Idiom Technologies Inc. to develop a separate plugin for generating PDFs. His FO plugin has since replaced the toolkit’s old implementation and become the “official” route for PDF generation. XML editors such as XMetal Author Enterprise Edition also use the FO plugin to produce PDFs.

The FO plugin uses the RenderX XEP Engine as its XSL-FO formatter. Its Personal Edition is available free online, but adds a discreet XEP watermark to the footer of generated PDFs. Purchasing a valid Personal Edition license provides a version that no longer generates the watermark.

Support for Apache FOP or other XSL-FO formatters has been announced several times, but has not progressed beyond announcements. The project is nevertheless gaining priority because all DITA Open Toolkit components are intended to be open source software.

The FO plugin provides a customization mechanism for both the XSLT stylesheets and attributes. In practice, customization is extremely difficult because the plugin ships with almost no documentation. A few Readme files explain installation, but the available information makes activating customization very difficult. There is also little information on which XSLT stylesheets or attribute sets format particular elements. Unlike DocBook, whose customization mechanism is documented in detail, the FO plugin still has much catching up to do.

Installation

The following explains how to install FO plugin 1.4.2 and integrate it into DITA Open Toolkit 1.4.2.1.

Complete installation of the FO plugin requires additional software:

  • The package icu4j.jar: an additional Java library used to improve index compilation. With FO plugin 1.4.2, the icu4j.jar package is optional.

  • RenderX XEP processor: the FO plugin uses RenderX as its XSL-FO processor.

Install the FO plugin as follows:

  1. Download the FO plugin from the Internet. FO plugin 1.4.2 requires the fo-1.4.2jdk1.5.zip file.

  2. Extract the zip file. A fo directory is created.

  3. Copy the fo directory into the toolkit’s demo directory.
    Next, download and install the additional software: the RenderX XEP processor and the Java library icu4j.jar from the Internet.

  4. Download the RenderX XEP processor from the Internet.
    The Personal Edition is free. Downloading requires a valid email address. After you enter it, a license key is sent to that address. The email also provides further download information for the RenderX XEP Personal Edition.

  5. Extract the zip file. It produces three files; one, with a name like setup-4.10-xxyyzz-personal.jar, is the RenderX XEP installer. Double-click the setup-4.10-xxyyzz-personal.jar file to start installation.

  6. Choose C:/ditaot14/demo/fo/lib/xep as the installation directory. Here, C:/ditaot14 is the toolkit’s root directory.

  7. Download the Java library icu4j.jar from the Internet.
    The latest stable version is 3.6.1. Therefore download the file icu4j_3_6_1.jar from the Internet.

  8. Copy the icu4j_3_6_1.jar file into the C:/ditaot14/demo/fo/lib/ directory and rename it icu4j.jar.
    All components are now installed. Finally, integrate the FO plugin into the toolkit using an ANT build file.

  9. Open the command line, for example by running the startcmd.bat file for the full package. Change to the toolkit’s root directory if you are not already there.

  10. Call the following ANT build file: ant -f integrator.xml.

If the message BUILD SUCCESSFUL appears, the FO plugin was successfully integrated into the toolkit.

Successful FO plugin integration

Figure: Successful FO plugin integration.

FO plugin files

The FO plugin contains both original files, such as XSLT stylesheets, and files created through customization.

Original files that can be customized are in the directories /demo/fo/cfg and demo/fo/xsl.

The following files and directories are available for customization:

  • demo/fo/cfg/catalog.xml: this catalog lists the files available for customization.

  • demo/fo/cfg/common/artwork: stores graphics used in headers, footers or warnings, for example. They are embedded in PDFs at 120 dpi.

  • demo/fo/cfg/common/index: contains index configuration files in different languages, for example to specify special-character sort order.

  • demo/fo/cfg/common/properties: contains a configuration file defining the encoding for the language used. The FO plugin specifies the value windows-1252 for German character encoding.

  • demo/fo/cfg/common/vars: contains configuration files in different languages for defining variables, for example in headers and footers.

  • demo/fo/cfg/fo/font-mappings.xml: specifies which fonts to use when generating PDFs.

  • demo/fo/cfg/fo/attrs: contains attribute-set files for modifying XSLT stylesheet attributes. For more about attribute sets, see Attribute sets.

  • demo/fo/cfg/fo/i18n: contains configuration files in different languages defining special characters such as the copyright sign.

  • demo/fo/cfg/fo/xsl/custom.xsl: specifies which customized XSLT stylesheets to use for PDF production. It is overridden by the file /demo/fo/Customization/fo/xsl/custom.xsl, which normally lists the customized stylesheets.

  • demo/fo/xsl: contains the plugin’s XSLT stylesheets. For more information, see “XSLT stylesheets”.

Customize the listed files by copying and then editing them. Store the copies in the demo/fo/Customization directory, which provides the following structure for customized files:

  • demo/fo/Customization/catalog.xml: this catalog defines which files were customized and where they are stored. Comment out the entries for the files and directories you want to use. The file demo/fo/Customization/catalog.xml overrides the file demo/fo/cfg/catalog.xml.

  • demo/fo/Customization/artwork: directory for new graphics in headers, footers, warnings and so on.

  • demo/fo/Customization/common/index: directory for the customized index configuration file.

  • demo/fo/Customization/common/vars: directory for customized variable-definition files.

  • demo/fo/Customization/fo/attrs: directory for customized attribute-set files. In the custom.xsl file, specify the customized attribute-set files to use. It overrides the file custom.xsl in the directory demo/fo/cfg/fo/attrs.

  • demo/fo/Customization/fo/i18n: directory for special-character configuration files.

  • demo/fo/Customization/fo/xsl: directory for customized XSLT stylesheets. In the custom.xsl file, specify the customized stylesheets to use. It overrides the file custom.xsl in the directory demo/fo/cfg/fo/xsl.

The demo/fo/lib directory contains additional Java files needed by the plugin to process XSLT stylesheets.

 

XSLT stylesheets

The plugin’s original XSLT stylesheets are in the xsl/fo directory. If the plugin is installed in the toolkit’s demo directory, its stylesheets are in the demo/fo/xsl/fo- directory.

Individual XSLT stylesheets perform different functions needed to create PDFs. Their roles are listed below. Sometimes a stylesheet’s name reveals its purpose; sometimes it does not.

  • artworks-preprocessor.xsl: XSLT stylesheet processing the document’s graphics.

  • bookmarks.xsl: XSLT stylesheet generating PDF bookmarks.

  • commons.xsl: defines elements within the document, such as block elements.

  • flagging.xsl: XSLT stylesheet processing conditional-processing attributes such as audience, product, platform or otherprops.

  • front-matter.xsl: XSLT stylesheet generating a book’s front matter.

  • hi-domain.xsl: XSLT stylesheet processing highlighting domain elements.

  • i18n-postprocess.xsl: XSLT stylesheet processing special characters.

  • index.xsl: XSLT stylesheet processing index entries and generating an index.

  • links.xsl: XSLT stylesheet processing links, such as related links.

  • lists.xsl: XSLT stylesheet processing all kinds of lists, such as numbered lists or the <steps> elements in task topics.

  • pr-domain.xsl: XSLT stylesheet processing programming domain elements.

  • preface.xsl: XSLT stylesheet processing a book’s preface.

  • root-processing.xsl: XSLT stylesheet processing the basic PDF structure.

  • static-content.xsl: XSLT stylesheet generating document headers and footers.

  • sw-domain.xsl: XSLT stylesheet processing software domain elements.

  • tables.xsl: XSLT stylesheet processing tables.

  • toc.xsl: XSLT stylesheet generating the table of contents.

  • ui-domain.xsl: XSLT stylesheet processing user interface domain elements.

In addition to these stylesheets, the demo/fo/xsl/fo directory also contains stylesheets whose filenames end in _1.0. These contain instructions specific to DITA 1.1.

FO plugin 1.4.2 can process bookmap elements, including generating a table of contents or glossary. In the plugin’s early days, this required extensive stylesheet customization. Such comprehensive changes are no longer needed with the current version. Customizing attribute sets alone often suffices to produce the desired PDF design.

If stylesheet customization is still necessary, see The customization mechanism for XSLT stylesheets and attribute sets for instructions on activating the plugin’s customization mechanism.

 

Attribute sets

Attribute-set files are in the demo/fo/cfg/fo/attrs directory. The following files contain attribute sets:

  • commons-attr.xsl: attributes for general elements such as paragraphs, headings and images.

  • front-matter-attr.xsl: attributes for front matter.

  • hi-domain-attr.xsl: attributes for highlighting domain elements.

  • index-attr.xsl: attributes for elements marking index entries.

  • links-attr.xsl: attributes for elements creating links.

  • list-attr.xsl: attributes for elements creating lists.

  • pr-domain-attr.xsl: attributes for programming domain elements.

  • static-content-attr.xsl: attributes for headers and footers.

  • tables-attr.xsl: attributes for tables.

  • toc-attr.xsl: attributes for the table of contents.

  • ui-domain.xsl: attributes for user interface domain elements.

The following example shows attribute-set syntax:

<xsl:attribute-set name="topic.title">
    <xsl:attribute name="font-family">Sans</xsl:attribute>
    <xsl:attribute name="border-bottom">3pt solid black</xsl:attribute>
    <xsl:attribute name="margin-top">0pc</xsl:attribute>
    <xsl:attribute name="margin-bottom">1.4pc</xsl:attribute>
    <xsl:attribute name="font-size">18pt</xsl:attribute>
    <xsl:attribute name="font-weight">bold</xsl:attribute>
    <xsl:attribute name="padding-top">1.4pc</xsl:attribute>
    <xsl:attribute name="keep-with-next.withincolumn">always</xsl:attribute>
</xsl:attribute-set>

The <xsl:attribute-set> element defines attributes. The name attribute names and uniquely identifies the attribute set. You can then search the XSLT stylesheets to find where it is used.

An <xsl:attribute> element defines an attribute, identified by the name attribute. Its name must match the name valid for the relevant element in the XSL-FO specification. For example, an <fo:block> element may have attributes such as background-color, border-top-style, font-style, hyphenate, break-after, margin-top, color and so on. The plugin’s attribute-set names do not always reveal the type of element they apply to. It matters whether attributes are defined for a block element such as <fo:block> or an inline element such as <fo:inline>. If in doubt, search the XSLT stylesheets for the attribute-set name.

The attribute value is the content of the <xsl:attribute> element. Possible values are those defined in the XSL-FO specification.

The files also contain many attribute sets with no attributes defined, for example in

<xsl:attribute-set name="note__label__note"></xsl:attribute-set>

To define valid attributes for these sets, it is often necessary to inspect the XSLT stylesheets to identify the element concerned.

The following explains how to activate attribute-set customization.

 

The customization mechanism for XSLT stylesheets and attribute sets

Customizing the FO plugin requires considerable trial and error to achieve the desired result, mainly because the relevant attribute sets must first be identified. Even with XSLT stylesheet changes, the place to make them is not immediately evident. More documentation would have been welcome.

Activating customization is straightforward. Proceed as follows:

  1. Rename the catalog.xml.orig file in the demo/fo/Customization- directory to catalog.xml.

  2. Comment out all entries for files and directories you will customize.

  3. To activate attribute-set customization, uncomment the following line:

<!--uri name="cfg:fo/attrs/custom.xsl" uri="fo/attrs/custom.xsl"/-->

The catalog.xml file then contains the following entry:

<uri name="cfg:fo/attrs/custom.xsl" uri="fo/attrs/custom.xsl"/>

To activate XSLT stylesheet customization, uncomment the following line:

<uri name="cfg:fo/xsl/custom.xsl" uri="fo/xsl/custom.xsl"/>

  1. Rename the custom.xsl.orig file in the demo/fo/Customization/attrs- directory to custom.xsl.

  2. Rename the custom.xsl.orig file in the demo/fo/Customization/fo/xsl- directory to custom.xsl.
    You can now modify attribute sets and XSLT stylesheets.

Both the custom.xsl file for attribute-set customization and the custom.xsl file for XSLT stylesheet customization initially contain only an empty stylesheet’s basic structure:

<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0"></xsl:stylesheet>

Write modified or new attribute sets in the demo/fo/Customization/attrs/custom.xsl file. The following shows a modified topic.title attribute set:

<?xml version="1.0" ?>    
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
    <xsl:attribute-set name="topic.title">
      <xsl:attribute name="font-family">Lucida Sans</xsl:attribute>
      <xsl:attribute name="margin-top">12mm</xsl:attribute>
      <xsl:attribute name="margin-bottom">4mm</xsl:attribute>
      <xsl:attribute name="font-size">24pt</xsl:attribute>
      <xsl:attribute name="font-weight">bold</xsl:attribute>
      <xsl:attribute name="keep-with-next.withincolumn">always</xsl:attribute>
    </xsl:attribute-set>
</xsl:stylesheet>

Similarly, write modified or new XSLT stylesheets in the demo/fo/Customization/fo/custom.xsl file.

The following stylesheet formats the <keyword> element on output according to the value of the otherprops attribute, using either the properties of the attribute set keyword_blau or those of the attribute set keyword_rot.

<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.1">
    <xsl:template match="*[contains(@class,‘ topic/keyword ‚)]">
        <xsl:choose>
            <xsl:when test="@otherprops='red'">
                <fo:inline xsl:use-attribute-sets="keyword_rot" id="{@id}">
                    <xsl:apply-templates/>
                </fo:inline>
            </xsl:when>
            <xsl:otherwise>
                <fo:inline xsl:use-attribute-sets="keyword_blau" id="{@id}">
                    <xsl:apply-templates/>
                </fo:inline>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>

Stylesheets for the specialized elements from Specialization can be created similarly.

Setting localization variables

The demo/fo/cfg/common/vars directory contains files storing language-dependent static text and localization variables. Static text serves, for example, as headings: “Content” for a table of contents or “Chapter” as part of a chapter heading. By default, static text and localization variables come from the English language file en_US.xml.

To modify static text or localization variables, copy from the demo/fo/cfg/common/vars directory the de_DE.xml file with German localization variables into the demo/fo/Customization/common/vars directory.

Next, tell the plugin to stop using the English localization file by default (the en_US.xml file) and instead use, for example, the German file (the de_DE.xml file).

Make this setting in the build.xml build file in the demo/fo-directory. Search for <property name=“document.locale“ value=“en_US“/> and replace the value en_US with de_DE.

  

 

 

 

back to top