Chapter 3. Manipulating DocBook Document Structure

DocBook files can be created manually or by tools. Sometimes tools create a structure which is inconvenient for some reasons or you have legacy documents which contain the “wrong” structure. This chapter shows how to restructure your DocBook document in the way you want.

Table of Contents
3.1. Introduction
3.2. Pretty-Printing DocBook Documents
3.3. Converting DocBook from Version 4 to Version 5
3.4. Converting DocBook from Version 5 to Version 4
3.5. Splitting DocBook Documents
3.6. Extracting One Element from DocBook Document
3.7. Transforming sectX Elements into section Elements
3.8. Transforming section Elements into sectX Elements
3.9. Transforming bridgehead Elements into section Elements
3.10. Moving Block Elements Outside of Paragraphs
3.11. Adding Index Entries (Semi-)Automatically
3.12. Including Revision Information from Version Control Systems
3.13. Creating an Acronym List
3.14. Splitting DocBook 5 Documents Into Topics
3.15. Assembling Topics
3.16. Creating an Assembly File Manually
3.17. Using Entities as Placeholders
3.18. Preserving Entities

The methods described in this chapter are mostly XSLT solutions where you can find more or less in any XSLT book. Actually, some ideas origin from SalMangano´s excellent XSLT Cookbook. However, the solutions in this chapter are targeted exclusively on DocBook.

Most of these solutions are based on an identity transformation stylesheet which is shown in Example 3.1, “copy.xsl.

Example 3.1. copy.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="node() | @*">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>  
</xsl:stylesheet>

This simple stylesheet copies everything from the input document to the output document without any modifications. Although it seems quite useless at a first glance, it reveals its full power when combining it with customizations.


Project@GitHubIssue#8