[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Determined to grok the built-in templates


Subject: [xsl] Determined to grok the built-in templates
From: Sebastian Tennant <sebyte@xxxxxxxxxxxxxxx>
Date: Fri, 03 Feb 2006 23:00:57 +0000

Given:

  <text>
    foo
  </text>

and this XSLT:

  <xsl:template match="*">
    template-match="*"
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="/">
    template-match="/"
    <xsl:apply-templates />
  </xsl:template>

the output is:

  template-match="/"

  template-match="*"

  foo

I believe I'm right in saying that together these two templates
overide(?) the built-in 'traversal' template, so precisely three templates
are in play; these two (above), and the 'text-copy' template:

  <xsl:template match="text()|@*">
    <xsl:value-of select=".">
  </xsl:template>

I'm probably already labouring under a miscomprehension of some sort,
but here's my understanding of the sequence of events:

#   Template        Current node-set          Result tree
-   --------        ----------------          -----------
1.  "/"             <text>foo</text>          template-match="/"
2.  "*"             [unchanged]             + template-match="*"
3.  'text-copy'     [unchanged]             + foo

Notes:

1. "/" is the best match, so it goes first, the <text> element (and
   its string value) becomes the current node set and the literal
   result text is appended to the result tree.

2. "*" comes next (not sure why) but as the <text> element has no
   children the current node set is unchanged, and the literal result
   element is appended to the result tree.

3. the 'text-copy' template brings up the rear and the text from the
   current node set is appended to the result tree.


How wrong am I?  :-/  Please don't say completely!

sdt


Current Thread