Chapter 5. The Template System

Norman Walsh

$Id: templates.xml,v 1.2 2005/03/07 22:15:03 bobstayton Exp $

Table of Contents

Changing the Article Title Page

Some parts of the DocBook XSL Stylesheets are actually generated using XSL Stylesheets. In particular, the formatting of title pages is generated using a special template system. The same template system will eventually allow you to easily customize bibliography entries and perhaps other parts of the system as well.

FIXME: there needs to be more introductory/explanatory text here!

Changing the Article Title Page

In order to demonstrate how this system works, let's consider how we can use it to change the format of article title pages.

By default, the stylesheets print the following elements on the article title page, in this order: title, subtitle, corpauthor, authorgroup, author, releaseinfo, copyright, legalnotice, pubdate, revision, revhistory, abstract. Suppose we want to put only the title, author, and edition elements on the title page, in the order that they appear in the articleinfo.

The “hard” (and wrong!) way to do it would be to edit titlepage.templates.xsl and make the changes by hand.

The easy and right way is to construct a template document that describes the order and sequence of elements that you want:

<t:templates xmlns:t="http://nwalsh.com/docbook/xsl/template/1.0"
             xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
             base-stylesheet="/path/to/html/docbook.xsl">

<t:titlepage element="article" wrapper="div" class="titlepage">
  <t:titlepage-content side="recto" order="document">
    <title predicate="[1]"/>
    <author/>
    <edition/>
  </t:titlepage-content>
</t:titlepage>
</t:templates>

Then process this document with the template/titlepage.xsl stylesheet. This will produce the following somewhat cryptic stylesheet:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<!-- This stylesheet was created by titlepage.xsl; do not edit it by hand. -->

<xsl:template name="article.titlepage.recto"><xsl:apply-templates mode="article.titlepage.recto.mode" select="(articleinfo/title|artheader/title|title)[1]|articleinfo/author|artheader/author|articleinfo/edition|artheader/edition"/>
</xsl:template>

<xsl:template name="article.titlepage">
  <div class="titlepage">
    <xsl:call-template name="article.titlepage.before.recto"/>
    <xsl:call-template name="article.titlepage.recto"/>
    <xsl:call-template name="article.titlepage.before.verso"/>
    <xsl:call-template name="article.titlepage.verso"/>
    <xsl:call-template name="article.titlepage.separator"/>
  </div>
</xsl:template>

</xsl:stylesheet>

Despite its cryptic appearance, it has the desired result. When you use xsl:include to include these generated templates into the main stylesheet, then they are used to format the title page elements. The elements are selected and processed in the order you specified.

If you want to change how the titlepage elements are formatted (as opposed to which ones are formatted), you have to write your own customization layer that overrides the template for the element in question in the “titlepage.mode” mode.