This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: XPath grammar questions
- From: "David N Bertoni/Cambridge/IBM" <david_n_bertoni at us dot ibm dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Sun, 17 Mar 2002 12:02:44 -0800
- Subject: Re: [xsl] XPath grammar questions
- Reply-to: xsl-list at lists dot mulberrytech dot com
> The first case is in a path submitted by Tobias Reif, that originated, as
I
> recall, from someone on this list:
>
> *[* and not(*/node()) and not(*[not(@style)]) and not(*/@style !=
*/@style)]
>
> Specifically, it's the 'not(*/node())' that I'm having trouble with. The
> XPath spec states that:
>
> not( boolean ) -> boolean
>
> This would imply that '*/node()' evaluates to a boolean. However, it
also
> states that paths such as:
>
> ancestor::node()
>
> evaluates to a set of matching nodes. Further, I had assumed that the
path:
>
> */node()
>
> by itself would also result in a set of nodes.
>
> I have a group of theories about this, but I'm not quite grokking the
intent
> of XPath. I don't see how the same path should evaluate to two different
> results. In any case, there have been a number of successful
implementations
> of XPath, so I know I'm missing something.
The rules for conversion are spelled out in the XPath recommendation,
although can get prettty convoluted. In this case, an empty node-set is
converted to the boolean value false, while a non-empty node-set is
converted to the boolean value true.
> The second (and at this point, more critical) problem I'm having is with
> function names. Take:
>
> [normalize-space(@name)='x']
>
> If you follow the grammar, the evaluation is:
>
> Predicate->Expr->OrExpr->AndExpr->EqualityExpr->RelationalExpr->
> AdditiveExpr
>
> at which point it matches the rule:
>
> AdditiveExpr:: AdditiveExpr '-' MultiplicativeExpr
> where you effectively have "normalize" "-" "space(@name)='x'".
Your tokenization is incorrect -- normalize-space is one token. See:
http://www.w3.org/TR/xpath#exprlex
In particular:
"When tokenizing, the longest possible token is always returned"
Also, see:
http://www.w3.org/TR/xpath#numbers
"The - operator performs subtraction.
NOTE: Since XML allows - in names, the - operator typically needs to be
preceded by whitespace. For example, foo-bar evaluates to a node-set
containing the child elements named foo-bar; foo - bar evaluates to the
difference of the result of converting the string-value of the first foo
child element to a number and the result of converting the string-value
of the first bar child to a number."
Dave
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list