XML technologies / DocBook / Generating (X)HTML / Formatting headings / Formatting sections
(Excerpt from "DocBook-XML: Media-neutral and platform-independent publishing" by Thomas Schraitle)
As with chapters and similar structures, numbering and titles are output together. The following procedure separates them and displays the number in white on a gray background. Proceed as follows:
Create a customization file as shown in Creating a customization file for (X)HTML. In this file, set the parameter
html.stylesheetto your CSS file (see Adding a reference to a CSS file).Copy the template
section.headingto your customization file. Depending on the output format, it is inhtml/sections.xslorxhtml/sections.xsl.Find the following code inside the template:
<xsl:copy-of select="$title"/>Replace the code from step 3 with these lines:
<xsl:choose>
<xsl:when test="$level = 1 and string($section.autolabel) != 0">
<span class="label">
<xsl:apply-templates select="$section" mode="label.markup"/>
</span>
<span class="title">
<xsl:apply-templates select="$section" mode="title.markup"/>
</span>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$title"/>
</xsl:otherwise>
</xsl:choose>Line 2: Checks whether this is a first-level section and whether the parameter
section.autolabelis set to 1. Numbering and title are separated only if both conditions hold.
Line 3: Generates the number and inserts it into aspanelement with aclassattribute. CSS can format the number.
Line 6: Like line 3, but for the title.
Line 10: If the conditions in line 2 do not hold, copy the title from the parametertitle.
Create a CSS file with the following rules. The figure below shows the result:
h2.title span.label {
color: white;
background-color:gray;
margin-right: 1ex;
padding-left: 0.25em;
padding-right: 0.25em;
}Figure: Separate numbering for a first-level section
Copyright © 2009 Millin Verlag
You may print the online version for your private use.
Otherwise, this chapter from "DocBook-XML: Medienneutrales und plattformunabhängiges Publizieren" is subject to the same provisions as the printed edition: the work, including all its parts, is protected by copyright. All rights are reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Millin Verlag, Siebengebirgsring 36, 53797 Lohmar, info(at)millin.de
back to top