Difficulty: ★★☆ (medium)
Keywords: assemblies, topic

Problem

You want to convert an assembly structure and its associated modular files into a single DocBook 5 file.

Solution

You need the following prerequisites:

  1. An assembly file. This starts with the assembly root element from DocBook 5.1. The assembly file contains references to all of your modules which composes your realized DocBook document. Or in other words: the assembly file maps the modules to structure.

  2. The assembly/assemble.xsl stylesheet from the DocBook XSL distribution. Get the latest version as it is added in 2012.

  3. Your module files based on DocBook 5.

Use xsltproc to create a single DocBook 5 (the variable DB contains the path of your DocBook XSL directory):

xsltproc \
    $DB/assembly/assemble.xsl \
    assembly.xml

Discussion

The assemble.xsl stylesheet contains several parameters to influence the assembling process:

Table 3.3. Parameters to Influence the Assembling Process
ParameterDescription
root.default.renderasSets the name of the root element of the assembled document, if not specified with renderas attribute
structure.idSelects one structure element from several; similar to the rootid parameter for the XHTML stylesheets
topic.default.renderasSets the name of the output element of any topic elements if not specified with renderas attribute
output.formatSelects which of the possible output formats are being generated. The value of this parameter should match on a format attribute on output elements.
output.typeSelects which structure element to process; the value should match with the type attribute on a structure element

The following subsections shows some specific examples to influence the assembling process.

Selecting a Structure by ID

For example, your assembly file looks like this:

<assembly version="5.1" xmlns="http://docbook.org/ns/docbook">
  <resources> ... </resources>
  <structure xml:id="quickstart"> ... </structure>
  <structure xml:id="reference"> ... </structure>
</assembly>

As you can see, you have two structure elements, one for a quick start, another for a reference. To process only the reference, set the parameter structure.id to the xml:id of the reference as follows:

xsltproc \
    --stringparam structure.id reference \
    $DB/assembly/assemble.xsl \
    assembly.xml

If you omit the structure.id parameter, the assemble.xsl stlyesheet selects always the first structure element.

Selecting a Structure by Type

For example, your assembly file looks like this:

<assembly version="5.1" xmlns="http://docbook.org/ns/docbook">
  <resources> ... </resources>
  <structure type="help.system"> ... </structure>
  <structure type="startup"> ... </structure>
</assembly>

As you can see, there are two structure elements, one for a help system, another for a startup. To process only the startup, set the parameter output.type as follows:

xsltproc \
    --stringparam output.type startup \
    $DB/assembly/assemble.xsl \
    assembly.xml

See Also


Project@GitHubIssue#8