Re: [xsl] Determined to grok the built-in templates

Subject: Re: [xsl] Determined to grok the built-in templates
From: David Carlisle <davidc@xxxxxxxxx>
Date: Sat, 4 Feb 2006 20:33:22 GMT
> I believe I'm right in saying that together these two templates
> overide(?) the built-in 'traversal' template, 

There are built in templates for each node type (document, element,
attribute, comment, processing-instruction, text) (in every mode)
You have defined two templates, one for elements and one for root nodes,
in the default mode, but all the other default templates are still
active, unless you define more templates.

> so precisely three templates
> are in play; these two (above), and the 'text-copy' template:

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

If you add that one then that is effectively the same as the default
template for text and attribute nodes.

The default templates for comments and processing instructions discards

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
I am not at all sure what you mean here. The current node list (not
there is no such thing as a "current node set")
is associated with the apply-templates select attribute, not with a
template. Each time a template fires there is a single current node
(taken from the current node list that has been selected by apply
templates, either with an explict select attribute, or with the default
selection (of / initially of child::node() otherwise)

given a document of


There are 3 nodes, a root node, an element node and a text node.

the initial node list is a list of one node (/) you have a template
matching that, so it is selcted and generates a text node with content
it uses apply-templates with its default select attribute of child::node
so the current node list is set to the children of /, in order, in this
case that is again a list of length 1, consisting of teh element node
with name text. The template matching * matches that, and produces a
second text node (which will be merged with the first as you can not
have two sibling text nodes) with content
template match="*"
Again the default section is used on apply templates so the current node
list is set to the children of teh element, in document order.
Again, in this case, this is a single node, the text node with the
content of the element.
That is matched by your template matching   <xsl:template
so this content is copied and produces a text node (which is again
merged with the existing text node)

> 1. "/" is the best match, so it goes first, the <text> element (and
no / is never an element it is the _parent_ of the top most element and
it represents the whole document.

This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:

Current Thread