XML technologies / DocBook / The DocBook XSL stylesheets / Customizing a title page directly / Structure and order

(Excerpt from "DocBook-XML: Media-neutral and platform-independent publishing" by Thomas Schraitle)

The DocBook stylesheets are structured so that changes always require customizing the same templates. This applies both to online formats (HTML, HTMLHelp, …) and to XSL-FO. The stylesheets contain templates called in a specific order to create the left (verso) and right (recto) sides of a title page. This matters only for XSL-FO. Online formats make no such distinction, and the verso templates are empty.

The following example examines these templates for the element article. The basic structure is the same for every DocBook structural element (see Structural elements). Simply replace article with the name of another element.

Example: Structure and order of an article title page

{html,fo}/component.xsl:
  <xsl:template match="article">
     <xsl:call-template name="article.titlepage"/>
     <!-- Inhaltsverzeichnis -->
  </xsl:template>

{html,fo}/titlepage.templates.xsl:
  <xsl:template name="article.titlepage.recto">
    <!-- title -->
    <!-- subtitle -->
    <!-- Titlepage Elemente -->
  </xsl:template>
  <xsl:template name="article.titlepage.verso"></xsl:template>
  <xsl:template name="article.titlepage.separator"></xsl:template>
  <xsl:template name="article.titlepage.before.recto"></xsl:template>
  <xsl:template name="article.titlepage.before.verso"></xsl:template>
  <xsl:template name="article.titlepage">
      <!-- recto.content -->
      <xsl:call-template name="article.titlepage.before.recto"/>
      <xsl:call-template name="article.titlepage.recto"/>
      <!-- verso.content -->
      <xsl:call-template name="article.titlepage.before.verso"/>
      <xsl:call-template name="article.titlepage.verso"/>
      <xsl:call-template name="article.titlepage.separator"/>
  </xsl:template>

{html,fo}/titlepage.xsl:
  <xsl:template match="..." mode="titlepage.mode">
    ...
  </xsl:template>

Line 2: Matches an article element. After the title page is created using article.titlepage, a table of contents is inserted if requested. (X)HTML also processes Footnotes, omitted from the displayed source. XSL-FO handles footnotes differently.
Line 8: Inserts objects on a recto page, in this case title or subtitle. A title may occur in several places, for an article in articleinfo, artheader, and so on. An article title page may contain other elements, such as author, copyright, and so on. These are inserted if present. Their order is shown in the example Excerpt from an article specification file, (X)HTML output. All elements in this template are processed in the mode article.titlepage.recto.auto.mode.
Line 13: Inserts objects on a verso page. Empty by default for (X)HTML and XSL-FO.
Line 14: Inserts objects at the end of article.titlepage to separate the title page from the rest of the document. For (X)HTML, the default output is <hr/>; for XSL-FO, this template is empty.
Line 15: Inserts objects on a recto page to appear before article.titlepage.recto. Empty by default for (X)HTML and XSL-FO.
Line 16: Inserts objects on a verso page to appear before article.titlepage.verso. Empty by default for (X)HTML and XSL-FO.
Line 17: Creates the title page by calling the previously defined templates in the specified order.
Line 28: Processes DocBook elements in the mode titlepage.mode.

As mentioned above, elements are first processed in a special mode, which for articles is article.titlepage.recto.auto.mode. This provides finer control and customization. This mode cascades through several other modes called in sequence:

article.titlepage.recto.auto.mode
article.titlepage.recto.mode
titlepage.mode
[kein Modus]

This cascade avoids defining every element for every mode. A default template is activated whenever an element is undefined in a mode, falling back to the next mode until it reaches the general titlepage.mode mode. The further down a mode appears, the more general it is.

This means that you must place customizations in the template with the appropriate mode. If you customize a title element in the mode titlepage.mode, the customization applies not only to an article but also to chapters, appendices, and other elements. Conversely, to customize a title element only for an article, write a template called in the mode article.titlepage.recto.mode.

The element title is used to explain the individual modes in more detail:

Example: Mode cascade for a title element in (X)HTML

{html,xhtml}/titlepage.templates.xsl:
<xsl:template match="title" mode="article.titlepage.recto.auto.mode">
  <div xsl:use-attribute-sets="article.titlepage.recto.style">
    <xsl:apply-templates select="." mode="article.titlepage.recto.mode"/>
  </div>
</xsl:template>

{html,xhtml}/titlepage.templates.xsl:
<xsl:template match="*" mode="article.titlepage.recto.mode">
  <!-- Wird ein Element in diesem Modus nicht gefunden -->
  <!-- versuche den allgemeinen Modus titlepage.mode -->
  <xsl:apply-templates select="." mode="titlepage.mode"/>    
</xsl:template>

{html,xhtml}/titlepage.xsl:
<xsl:template match="title" mode="titlepage.mode">
  <h1>
    <xsl:apply-templates mode="titlepage.mode"/>
  </h1>
</xsl:template>

Line 2: Called by the template article.titlepage.recto. For (X)HTML, outputs a div element with appropriate attributes and continues processing in the mode article.titlepage.recto.mode. You normally do not customize this mode.
Line 9: Since no template exists for a title in the mode article.titlepage.recto.mode, the default template is called. This mode is a suitable place for your customizations.
Line 16: Default template for all title elements. It outputs an h1 element with additional attributes, omitted from the code. Any further elements inside a title are also processed in the mode titlepage.mode.

The following pages provide examples of solving common problems using the templates above.

  

back to top