6.7. Example: Barebones DocBook
Let's turn our attention to a larger example. We first mentioned DocBook in Example 2.4 as an example of an XML markup language. In Example 5.3, we outlined a DTD for a simplified version of the document type, which we called Barebones DocBook. Example 6.7 shows you how to write a large XSLT stylesheet to translate a Barebones DocBook document into HTML.
In this example, we use the XT XSLT transformation program by James Clark, which is written in Java and fairly easy to set up and use. There is one XT-specific feature that creates multiple files of output; the <xt:document> element tells the processor to redirect its output to a file given by the href attribute, using the method in the method attribute (e.g., HTML, XML, or text). In XSLT, any time you use a specialized control element such as <xt:document>, you need to specify the namespace first, as we did in the <xsl:stylesheet> element.
Running the transformation on the document in Example 2.4, the result is a collection of HTML pages: one for the preface, two for the chapters, and another for the appendix. Figure 6.3 shows a page from this new document.
Figure 6.3. A page produced from the transformation
Example 6.7. XSLT Stylesheet to Convert Barebones DocBook to HTML
<?xml version="1.0"?> <!-- ======================================================================== XSLT Stylesheet ... |
Get Learning XML now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.