Thursday, October 18, 2007

XPath features

hard to recognize at the first try feature of XPath

//x[position()=1]

and

/descendant-or-self::x[position()=1]

return different answers. This becomes more clear when "//" is replaced with what it stands for:

/descendant-or-self::node()/x[position()=1]

This suggests two things that need to be addressed when XPath is covered in class:

  • Location steps are evaluated in their full, each input node from the sequence (nodelist) at a time.
  • The exact verbose equivalent to "//" is "/descendant-or-self::node()/", which means that any //x expression is actually two location steps, not one.


O'Reiley's book on XQuery actually has this example.

No comments: