(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
<<<  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15    >>>