Subject: Re: XSLT Processing Model Questions
From: Peter Davis <pdavis152@xxxxxxxxx>
Date: Fri, 12 Apr 2002 20:19:16 -0700
|
On Friday 12 April 2002 21:55, Dietrich Ayala wrote:
> Now, in this template, the source tree context node is still the root
> (/doc[1]), right? So how does this match anything, as the match expression
> seems like it would match any "doc" children of the context node?
>
> <xsl:template match="doc/title">
> <h1>
> <xsl:apply-templates/>
> </h1>
> </xsl:template>
>
> I think I'll stop there. Because if my understanding of how the initial
> context node and source-tree-nodes-to-be-processed are flawed, then it only
> goes downhill from here :)
The reason it works is because there is a different between *match*
expressions and *select* expressions. In match expressions (template
match="..."), the context node does not affect the result. Here,
match="doc/title" simply means to match <title> elements that are immediate
children of a <doc> element, regardless of what the current context is. Once
the <title> is matched, the <title> becomes the context node within the
template; the "doc/" is only a restriction on which <title>s can be matched.
Think of match expressions as going in reverse. Here are the basic steps:
* apply-templates selects a <title> node (as a child of the context node).
* The template tries to match "title" to the selected node. So far so good.
* The template looks to see if the <title> also has a <doc> parent. So far so
good.
* Everything has matched successfully, so the template executes with the
<title> as the context node.
On the other hand, in expressions like in
<xsl:apply-templates select="child::node()"/> (the equivilant of what you
have), are relative to the context node, as you know. But this only selects
the nodes; the act of matching them to a template is a totally different
process (read the XPath spec; these two types of expressions even have
different grammars, although they are very similar).
--
Peter Davis
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
- patial sums, (continued)
- Vrajitoru - Fri, 12 Apr 2002 01:55:06 -0400 (EDT)
- Dietrich Ayala - Fri, 12 Apr 2002 21:43:26 -0400 (EDT)
- Peter Davis - Fri, 12 Apr 2002 23:14:30 -0400 (EDT) <=
|
|