XML technologies / DocBook / Generating FO (PDF) / Formatting headings / Formatting sections

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

As shown in Formatting sections in the chapter "Generating (X)HTML", for XSL-FO use the same template section.heading. Proceed as follows:

  1. Create a customization file as shown in Creating a customization file for XSL-FO.

  2. Copy the template section.heading from the file fo/sections.xsl into your customization file.

  3. Find the following code inside the template:

<xsl:choose> 
    <xsl:when test="$level=1"> 
        <fo:block xsl:use-attribute-sets="section.title.level1.properties"> 
            <xsl:copy-of select="$title"/> 
        </fo:block> 
    </xsl:when> 
    <!-- Weitere xsl:when-Elemente --> 
</xsl:choose>

  1. Replace the code in the first xsl:when branch with the following lines:

<xsl:when test="$level=1"> 
    <fo:block xsl:use-attribute-sets="section.title.level1.properties">
        <xsl:if test="number($section.autolabel) != 0">
            <fo:inline xsl:use-attribute-sets="section.label.level1.properties"> 
                <xsl:apply-templates select=".." mode="label.markup"/> 
            </fo:inline> 
        </xsl:if> 
        <fo:inline>
            <xsl:apply-templates select="." mode="title.markup"/> 
        </fo:inline> 
    </fo:block> 
</xsl:when>

Line 2: Wraps the numbering and title.
Line 3: Checks whether the parameter section.autolabel is set to 1. If numbering is enabled, a fo:inline element containing the number is generated.
Line 8: Generates the title. In the fo:inline element, you can add attributes or an attribute set, as with the preceding inline element.

  1. Customize the numbering using the following attribute sets:

<xsl:attribute-set name="section.label.level1.properties"> 
    <xsl:attribute name="color">white</xsl:attribute> 
    <xsl:attribute name="background-color">gray</xsl:attribute> 
    <xsl:attribute name="padding-left">0.25em</xsl:attribute> 
    <xsl:attribute name="padding-right">0.25em</xsl:attribute> 
    <xsl:attribute name="space-end">1em</xsl:attribute> 
</xsl:attribute-set>

  

back to top