(Q21) Prepare a table of contents for the document "cookbook.xml", containing nested sections and their titles.
LET $b := document("cookbook.xml")
RETURN
<toc>
filter($b, $b//section | $b//section/title | $b//section/title/text() )
</toc>
XSLT equivalent to (Q21)
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<toc>
<xsl:apply-templates select="document('cookbook.xml')/node()"/>
</toc>
</xsl:template>
<xsl:template match="section | section/title | section/title/text()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="* | text()"/>
</xsl:transform>
- An XSLT solution that employs the implicit, automatic recursion of template rules
|