|
|
|---|
<xsl:template match="section[ @slot='main']">
This template will match only section elements
which have an attribute named slot whose value
is main
<p>
<xsl:call-template name="toc"/>
paste in the output of the named template called toc.
</p>
<xsl:apply-templates select="section">
<xsl:sort select="title"/>
Apply templates in this stylesheet to sections
which are children of this section, sorted
alphabetically by their title sub-element
</xsl:apply-templates> </xsl:template> <xsl:template name="toc">
This is the named template which was called earlier. Most templates are not named: they are applied automatically if their patterns match an element
<xsl:for-each select="section">
for-each iterates over matching elements in turn
<xsl:sort select="title"/>
<a>
<xsl:attribute name="href">#<xsl:value-of select="title"/>
</xsl:attribute>
xsl:attribute allows us to construct the value of an attribute of the enclosing tag
<xsl:value-of select="title"/>
</a> |
</xsl:for-each>
</xsl:template>
|
|
|