RE: XPath 2.0 -- StepExpr question

> Michael,
> 
> Thanks for the quick reply.
> 
> Perhaps I chose a bad example.  I still don't see the use of 
> allowing a 
> PrimaryExpr as a StepExpr.  Since it was just added to the 
> WD, I assume 
> there was a good use for it.  Can you show an example?
> 

Sure,

(1)   document('a.xml')/id('a123')
(2)   book/(chapter|appendix)/section

Also

(3)   $x/(/)
though we also provide the more comfortable syntax xf:root($x) for this
one...

Basically, there is no good reason to treat "/" differently from any other
operator. Syntactically, its operands can be any expression, and restricting
the operands is done through type rules, not by using the grammar.

There is one slightly unfortunate consequence, which is that it's legal to
write things on the rhs of "/" that don't depend on the context node, for
example

(4)  document('a.xml')/document('b.xml')
(5)  book/$param   {--legal if $param is a node-sequence --}

In this case, the lh operand is effectively ignored. I think there's a good
case for implementations to produce warnings when such constructs are used:
it's similar to the problem that occurs in XSLT 1.0 when people write
<xsl:sort select="$param"/>, and the most likely explanation is the same -
because of the "$" sign, many beginners imagine that variables are macros.

Michael Kay

Received on Monday, 23 September 2002 14:50:09 UTC