XML technologies / DocBook / The DocBook XSL stylesheets / Customizing DocBook XSL stylesheets / A customization file for the DocBook stylesheets

(Excerpt from "DocBook-XML: Medienneutrales und plattformunabhängiges Publizieren" by Thomas Schraitle)

For a large number of parameters or for templates, you need a customization file. The minimum contents of this file are the root element xsl:stylesheet, an import instruction for the original stylesheets, and the relevant parameters or customized template rules.

A customization file offers the following advantages:

Your customization file needs a different base URI depending on the DocBook version you process. A base URI lets you reference the original stylesheets independently of the platform, much like identifiers in a DTD.

 

Table: Base URIs for DocBook 4 and DocBook 5

DocBook 4

"http://docbook.sourceforge.net/release/xsl/current/"

DocBook 5

"http://docbook.sourceforge.net/release/xsl-ns/current"/

For DocBook 4, your customization file looks like the following example:

Example: Structure of a customization file for DocBook 4 (customize-db4.xsl)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:import href="http://docbook.sourceforge.net/release/xsl/current/FORMAT/docbook.xsl"/>
  <!-- Überschreiben von Parametern -->
  <xsl:param name="admon.graphics" select="1"/>
  <xsl:template match="command">
    <!-- ... -->
  </xsl:template>
</xsl:stylesheet> 

A customization file for DocBook 5 looks as follows:

Example: Structure of a customization file for DocBook 5 (customize-db5.xsl)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:d="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" exclude-result-prefixes="d xlink"> 
  <xsl:import href="http://docbook.sourceforge.net/release/xsl-ns/current/FORMAT/docbook.xsl"/>
    <!-- Überschreiben von Parametern -->
  <xsl:param name="admon.graphics" select="1"/>
  <xsl:template match="d:command">
    <!-- ... -->
  </xsl:template>
</xsl:stylesheet>

Line 2: The DocBook 5 namespace is required. The namespace of XLink (prefix xi). You need it to access XLink attributes such as xlink:href. The exclude-result-prefixes attribute prevents the declared Namespaces from being copied into the output format.
Line 3: The DocBook XSL NS stylesheets require a slightly different URI from the DocBook 4 stylesheets. Replace FORMAT with the target format you want to generate. Possible replacements are eclipse, epub, fo, html, htmlhelp, javahelp, manpages, xhtml or xhtml-1_1.
Line 5: Many DocBook stylesheet parameters are independent of the stylesheet variant or output format.
Line 6: Each DocBook 5 element must have the declared prefix added (here d). Wherever XSLT searches for DocBook 5 elements, the prefix is required. Without it, the element is not recognized and the template rule is not applied, leading to unwanted results.

Where you store your customization file is a matter of preference. Some users keep it in the same directory as their XML documents; others store it in a more central location. The location is secondary; what matters is that you invoke the customization file so that it takes effect.

  

back to top