XML technologies / DocBook / Generating (X)HTML / Formatting headings / Formatting structural elements

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

Titles of chapters, appendices and other structural elements are formatted by the template named component.title. It includes the name, such as chapter or appendix, the number and the title. To format number and title separately, customize this template as follows:

  1. Create a customization file as shown in Creating a customization file for (X)HTML. In this file, set the parameter html.stylesheet to your CSS file (see Adding a reference to a CSS file).

  2. Copy the template named component.title to your customization file. Depending on the output format, it is in html/component.xsl or xhtml/component.xsl.

  3. Find the following code inside the template:

<xsl:apply-templates select="$node" mode="object.title.markup"> 
    <xsl:with-param name="allow-anchors" select="1"/> 
</xsl:apply-templates>

  1. Replace the code from step 3 with these lines:

<div class="component-title">
  <h1 class="label">
    <xsl:apply-templates select="$node" mode="label.markup"/>
  </h1> 
  <h1 class="title">
    <xsl:apply-templates select="$node" mode="title.markup"/>
  </h1> 
</div>

Line 1: Groups number and title in a div, allowing the whole group to be formatted.
Lines 2 and 5: Create an h1 element for the number and title respectively. The additional class attribute allows individual CSS formatting.
Line 3: Gets the current component’s number.
Line 6: Gets the current component’s title.

  1. Create a CSS file. These rules were taken from the DocBook website and slightly modified. They move the number and title to the right edge, making the number very large:

div.component-title { 
  text-align: right; 
} 
h1.label { 
  font-size: 900%; 
  font-weight: normal; 
  font-family: sans-serif; 
  margin-bottom: 0px; 
  padding-bottom: 0px; 
  margin-top: 0px; 
  padding-top: 0px; 
} 
div.component-title h1.title { 
  font-family: sans-serif; 
  font-size: 200%; 
  margin-top: 0px; 
  padding-top: 0px; 
  margin-right: 20px; 
}

The following figure shows the result (text from Wikipedia).

Separating number and title

Figure: Separating number and title

  

back to top