Re: XPath attributes

Hi Cliff,

> Looking at the XPath Recommendation, it appears that the notation
>
> element[@attribute]
>
> is not actually supported by the grammar.

I think that it is. In XPath 1.0, predicates are specified with:

[8]    Predicate        ::=    '[' PredicateExpr ']'
[9]    PredicateExpr    ::=    Expr  

Then expressions are specified with a series of productions, as
follows:

[14]    Expr                  ::=    OrExpr
[21]    OrExpr                ::=    AndExpr
                                     | ...
[22]    AndExpr               ::=    EqualityExpr
                                     | ...
[23]    EqualityExpr          ::=    RelationalExpr
                                     | ...
[24]    RelationalExpr        ::=    AdditiveExpr
                                     | ...
[25]    AdditiveExpr          ::=    MultiplicativeExpr
                                     | ...
[26]    MultiplicativeExpr    ::=    UnaryExpr  
                                     | ...
[27]    UnaryExpr             ::=    UnionExpr
                                     | ...
[18]    UnionExpr             ::=    PathExpr
                                     | ...

So eventually you get to path expressions, which can be location
paths:
                                     
[19]    PathExpr              ::=    LocationPath
                                     | ...

The @attribute in the example above is a relative location path:
                                     
[1]    LocationPath            ::=    RelativeLocationPath
                                      | ...
[3]    RelativeLocationPath    ::=    Step
                                      | ...

The Step is made up of an AxisSpecifier, a NodeTest and a Predicate.
You seem to be interested in the AxisSpecifier:
                                      
[4]    Step                         ::=    AxisSpecifier NodeTest Predicate*
                                           | ...
[5]    AxisSpecifier                ::=    AxisName '::'
                                           | AbbreviatedAxisSpecifier
[6]    AxisName                     ::=    ...
                                           | 'attribute'
                                           ...
[13]    AbbreviatedAxisSpecifier    ::=    '@'?

So I think that XPath does support that syntax.

> In particular, I was looking at the grammar to see if the following
> statements would return the same results, albeit through different
> mechanism (I assume they would, maybe someone can comment):
>
> a/@b
> a/attribute::b

These return a node set containing the b attributes on the a elements
that are children of the context node.

> a[@b]
> a[attribute::b]

These return a node set containing the a elements that are children of
the context node and that have b attributes.

When you use a predicate, you filter a node set - the node set still
returns the same kind of node as it would without the predicate, but
returns only some of those nodes.

I hope that clears up your misapprehensions. Questions about what
XPath can and can't do, and what different paths mean are best
addressed to the XSL-List (http://www.mulberrytech.com/xsl/xsl-list).

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Tuesday, 26 February 2002 13:28:09 UTC