This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: //* and position()


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() < 3], this is an abbreviation for

	/descendents-or-self::node()/child::*[position() < 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() < 3] (equivalent to
(//*)[position() < 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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]