An alternative XSLT equivalent to (Q21) (no template rules)

<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <toc>
      <xsl:call-template name="filter">
        <xsl:with-param name="first" select="document('cookbook.xml')"/>
        <xsl:with-param name="second"
                        select="//section | //section/title | //section/title/text()"/>
      </xsl:call-template>
    </toc>
  </xsl:template>
  <xsl:template name="filter">
    <xsl:param name="first"/>
    <xsl:param name="second"/>
    <xsl:for-each select="$first/node()">
      <xsl:choose>
        <xsl:when test="count(.|$second)=count($second)">
          <xsl:copy>
            <xsl:call-template name="FILTER">
              <xsl:with-param name="first" select="."/>
              <xsl:with-param name="second" select="$second"/>
            </xsl:call-template>
          </xsl:copy>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="FILTER">
            <xsl:with-param name="first" select="."/>
            <xsl:with-param name="second" select="$second"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
  </xsl:template>
</xsl:transform>
  • An alternative XSLT solution that employs explicit recursion, through a named template. filter() could also be defined this way in XQuery, using a recursive function definition.
<<<  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15    >>>