Re: Context node/Predicates in Expressions

Subject: Re: Context node/Predicates in Expressions
From: Mike Brown <mike@xxxxxxxx>
Date: Fri, 26 May 2000 00:34:09 -0600 (MDT)
> I can see that preceding::foo[1] returns the first foo element in reverse
> order--by this I am given to understand, the foo immediately preceding the
> context node.  However, in  (preceding::foo)[1], I do not understand the
> "discursive meaning" (cf. my prev. post looking for a human-readable
> meaning of "::") of the ()'s in this such that preceding::foo, when in
> ()'s, is child axis . . . 

foo[1] =
child::foo[1] =

  the node at position 1, from the set of all nodes matching this pattern:
  {
    from the set of document-ordered nodes along the child axis, relative
    to the context node, only those nodes that match this pattern:
    {
      are elements named foo and are in the null namespace
    }
  }

Now consider this one:

(child::foo | preceding::bar)[1] =
child::(child::foo | preceding::bar)[1] =

  the node at position 1, from the set of all nodes matching this pattern:
  {
    from the set of document-ordered nodes along the child axis, relative
    to the context node, only those nodes that match this pattern:
    {
      the union of 1. the set of nodes matching this pattern:
      {
        from the set of document-ordered nodes along the child axis,
        relative to the context node, only those nodes that match this
        pattern:
        {
          are elements named foo and are in the null namespace
        }
      }
      and 2. the set of nodes matching this pattern:
      {
        from the set of reverse-document-ordered nodes along the
        preceding axis, relative to the context node, only those nodes
        that match this pattern:
        {
          are elements named bar and are in the null namespace
        }
      }
    }
  }

> It could be that I'm not "getting" the notion of context node.
> I'm working for the assumption that, in such a stylesheet with a first
> template of:
> 
> <xsl:template match="body">
> 
> The context node --unless something else has been specified-- is the
> document root, correct?  Sort of "by default" -- rather than, for
> instance, the root element.

No. Which template comes first makes no difference. XSLT processing begins
at the root node of the source tree. The template that best matches this
node is found (and per the spec is a built-in template, unless you
override it with one of your own) and its instructions are executed.

The instructions may include xsl:apply-templates, which identify a new set
of nodes to go find and instantiate the best templates for. Thus recursive
processing can occur. When an xsl:template or xsl:for-each iteration is
instantiated, there is, among other things, a context node: the node being
processed. But the context node only applies to the instructions in the
template or for-each block, not to the template itself.

The match attribute on xsl:template, unlike the select attribute on other
instructions, is a pattern does not have a context node; it is the 'foo'
in hrrrm::foo, where hrrrm is an axis (whose name I just made up) that
contains only the nodes that are in the current node list: the nodes that
have been identified for processing by an xsl:apply-templates instruction.
At least, that's one way of looking at it.

So match="body" will match any element named body in the null namespace,
from the set of nodes in the current node list, and should not be
interpreted as child::body relative to one node in particular.

   - Mike
___________________________________________________________
Mike J. Brown, software engineer, Webb Interactive Services
XML/XSL stuff: http://www.skew.org/    http://www.webb.net/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread