XML technologies / DocBook / Generating (X)HTML / Editing headers and footers / Adding breadcrumbs
(Excerpt from "DocBook-XML: Media-neutral and platform-independent publishing" by Thomas Schraitle)
Breadcrumb navigation shows the path to the current element, helping readers navigate deeply nested structures. Its name comes from Hansel and Gretel and their trail of breadcrumbs through the forest.
First create a customization file as shown in Creating a customization file for (X)HTML.
Add a parameter to enable or disable breadcrumb navigation as needed. It is enabled by default:
<xsl:param name="generate.breadcrumbs" select="1"/> Add another parameter for the separator between path components. Choose any separator you like:
<xsl:param name="breadcrumbs.separator">
<xsl:text> » </xsl:text>
</xsl:param>Add the call to the normally empty template
user.header.content. The parametergenerate.breadcrumbschecks whether breadcrumbs are wanted, creates adivelement and inserts the navigation:
<xsl:template name="user.header.content">
<xsl:if test="$generate.breadcrumbs != 0">
<div class="userheadercontent">
<xsl:call-template name="generate-breadcrumb"/>
</div>
</xsl:if>
</xsl:template>Create the template
generate-breadcrumb:
<xsl:template name="generate-breadcrumb">
<div class="breadcrumb">
<p>
<xsl:for-each select="ancestor::*">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:call-template name="href.target">
<xsl:with-param name="object" select="."/>
<xsl:with-param name="context" select="."/>
</xsl:call-template>
</xsl:attribute>
<xsl:apply-templates select="." mode="title.markup"/>
</xsl:element>
<xsl:copy-of select="$breadcrumbs.separator"/>
</xsl:for-each>
<xsl:if test="self::* != /*">
<strong>
<xsl:apply-templates select="." mode="title.markup"/>
</strong>
</xsl:if>
</p>
</div>
</xsl:template>Line 2: The complete breadcrumb navigation is wrapped in a
divelement with a correspondingclassattribute for CSS customization.
Line 3: The navigation itself is in a paragraph element.
Line 4: Iterates over all ancestors.
Line 5: Creates anaelement linking to the current ancestor.
Line 6: Creates anhreffor the precedingaelement.
Line 7: Inserts the current ancestor’s filename by calling the templatehref.target(especially important for chunked output).
Line 12: Inserts the current ancestor’s title.
Line 14: Copies the separator between breadcrumb items.
Line 16: Checks that the current element is not a root node; if so, inserts the current page’s title.
The following CSS rule illustrates inline alignment:
div.breadcrumbs > p {
display: inline;
} DocBook-XML » Transformationen » Transformieren nach (X)HTML
Display: Breadcrumb navigation
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