<book title="Sample book">
<chapter title="First chapter">
<section title="Section in first chapter">
<section title="Chunk of text within a section">
<para>My paragraph</para>
</section>
</section>
</chapter>
</book>
The section elements can be nested
You could use the following template to display the breadcrumbs in front of each heading:
<xsl:template match="chapter|section">
<p class='crumbs'>
Walk through all the ancestors, starting from the root element
<xsl:for-each select="ancestor::*">
If the current element has an ancestor, we've obviously printed something already, so insert a breadcrumb separator …
<xsl:if test="ancestor::*"><xsl:text>, </xsl:text></xsl:if>
… and display the title of the ancestor element.
<xsl:value-of select="@title" />
</xsl:for-each>
</p>
At the end, display the current heading and recursively process child elements.
<h2><xsl:value-of select="@title" /></h2>
<xsl:apply-templates />
</xsl:template>
No comments:
Post a Comment