XML technologies / DocBook / The DocBook XSL stylesheets / Customizing DocBook XSL stylesheets / How to customize the DocBook stylesheets
(Excerpt from "DocBook-XML: Medienneutrales und plattformunabhängiges Publizieren" by Thomas Schraitle)
The previous sections showed how to introduce changes into the stylesheets, but not the general workflow. The following instructions describe a general approach to customizing the DocBook stylesheets:
Which DocBook version?
First establish which DocBook version you are writing in. Choose your customization file as shown in A customization file for the DocBook stylesheets.Checking existing parameters
Before customizing templates, check whether your problem can be solved with the existing parameters in DocBook XSL Stylesheets: Reference Documentation.Copying from the original
If parameters do not help, first identify the relevant template. For example, to customize the elementcommand, search for it in the DocBook stylesheets; you will find it in the fileinline.xsl.Adding the changes
Copy the template you found into your customization file and modify it as required.Consult DocBook XSL: The Complete Guide
If you get stuck, look for a solution in Bob Stayton’s book.Test your customization
Check whether your template is called by outputting a diagnostic message withxsl:message.
In the author’s experience, the following practices have proved useful when customizing the DocBook stylesheets:
Use parameters for “constants”: Most values entered in a stylesheet, such as colors, fonts, and font styles, are more variable than constant. Introduce parameters for these values so that they can be adjusted from the command line as needed. This also improves the consistency of your XSLT code.
Document parameters: An old recommendation that remains valid: document parameters and their allowed values in XML comments. If you need documentation for your customization, so-called “literate programming” can help. Norman Walsh describes this technique. The DocBook stylesheets are documented this way.
Use attribute sets: The DocBook stylesheets use attribute sets to group attributes under a common name. Especially with XSL-FO and its many attributes, this provides consistent notation. Therefore, use attribute sets both to override or extend existing sets and for your own attributes.
Limit
xsl:for-each: Usexsl:for-eachfor cases with a very strict content model, such assimplelist. In most cases, it is better to usexsl:apply-templates.Modularize your customization file: For extensive customizations, split your customization file into several stylesheets. Include them in the main stylesheet using
xsl:include. It is advisable to use the same filenames as the original stylesheets. This improves clarity and lets you immediately see which files contain customizations.
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