RE: Path Expression question

> A question about path expressions:
> 
> "/" is a legal expression
> "/ + 5" also seems to be legal
> 
> so,
> 
> "(/) * 5" is probably legal
> "(/) div 5" likewise
> 
> what about
> 
> "/ * 5" or "/ div 5"
> 
> Do we require spaces? Or parentheses? Or does an xpath parser 
> need to look ahead to distinguish these cases? (My vote is 
> for parentheses).

My understanding is that we require parentheses, but I'm not sure this is
clearly documented. The examples above are actually all legal in XPath 1.0,
which has a known bug in that it doesn't describe how to disambiguate these
cases. Fortunately none of the above examples is likely to appear often in
real code. In XPath 2.0, though, it becomes more likely: for example "if (/
is $n)" needs to be written as "if ((/) is $n)", or perhaps as "if (/. is
$n)". Or you can always write root(.)!

Michael Kay

Received on Thursday, 26 June 2003 11:49:56 UTC