Interpretation of (preceding::foo)[1]

Subject: Interpretation of (preceding::foo)[1]
From: "Paul W. Abrahams" <abrahams@xxxxxxxxxxx>
Date: Wed, 01 Dec 1999 23:49:09 -0500
The XPath spec, Sec. 3.3.(Node-sets) contains this note:

The meaning of a Predicate depends crucially on which axis applies.
For example, preceding::foo[1] returns the first foo element in
reverse document order, because the axis that applies to the [1]
predicate is the preceding axis;
by contrast, (preceding::foo)[1] returns the first foo element in
document order, because the axis that applies to the [1] predicate is
the child axis.

The note seems to be ambiguous in that it doesn't say whether the two
specifiers are being considered as expressions or as location paths,
but there are problems of interpretation either way.

If they are considered as expressions, then preceding::foo[1] is a
location path treated as an expression while (preceding::foo)[1] is
directly an expression consisting of the parenthesized expr
(preceding::foo) narrowed by the predicate[1], and the child axis
isn't applied, despite what the note says.

But if they are considered as location paths, then the location path
(preceding::foo)[1] seems to be an abbreviation of the location path
child::(preceding::foo)[1], and the selected nodes, order aside, are
the children of foo nodes rather than the foo nodes themselves.  In
this case the two node-sets to which the [1] predicate is applied are
quite different.

Am I misunderstanding this note or is there really something wrong
with it?

Paul Abrahams



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


Current Thread