Re: //* and position()

Subject: Re: //* and position()
From: Gary L Peskin <garyp@xxxxxxxxxxxx>
Date: Wed, 06 Sep 2000 23:35:12 -0700
Mike Brown wrote:
> 
> Someone explain this to me:
> 
> [snip]

Mike --

This points out the difference between using a predicate as part of a
location step (Xpath production [4]) and using a predicate as part of a
FilterExpr (Xpath production [20]).

In the case of //*[position() &lt; 3], this is an abbreviation for

	/descendents-or-self::node()/child::*[position() &lt; 3]

In other words, this will select any node that is one of the first two
children of another node.  This is how a predicate is used as part of a
location step.

In the case of $all_elements[position() &lt; 3] (equivalent to
(//*)[position() &lt; 3]), this will select the first two items in the
node-set $all-elements.

As Mike Kay mentions in his excellent book (at p. 382 at the bottom), []
binds more tightly than /.

>The first and 3rd methods return all elements, regardless of position.

Well, not really, depending on your input XML.  They any node that is
one of the first two children of another node.  If none of your nodes
have more than two children, the first and 3rd methods will return all
elements.  Try adding a third child to one of your nodes and you'll see
that it won't be returned.

HTH,
Gary


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


Current Thread