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 changes are retained when a new version of the DocBook stylesheets is installed on your system. Depending on how extensive your customizations are, you may also benefit from bug fixes or new features in the original stylesheets.
A customization file can be stored anywhere you have write access. This may not be possible when changing the original stylesheets.
Your changes and the original version are separate, making them easier to distinguish than with direct modifications.
The original version remains intact, so other users retain a familiar system whose behavior does not suddenly change.
A customization file is the only way to override templates and attribute sets.
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 | |
DocBook 5 | |
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.
Copyright © 2009 Millin Verlag
You may print the online version for your private use.
Otherwise, this chapter from "DocBook-XML: Medienneutrales und plattformunabhängiges Publizieren" is subject to the same provisions as the printed edition: the work, including all its parts, is protected by copyright. All rights are reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Millin Verlag, Siebengebirgsring 36, 53797 Lohmar, info(at)millin.de
back to top