Variable references in path expressions

Hi all

I have some questions about variable references appearing in path 
expressions and, in particular, how node identity, variable binding, and 
element constructors actually "work" in this context. Insights into this 
would be appreciated!

Consider the path expression $a/$b. 

If $a is a singleton, then the expression is equivalent to $b.

However, if $a is not a singleton, then a query such as

    let
      $a := (<a1/>, <a2/>, <a3/>),
      $b := (1, 2, 3)
    return
      $a/$b

will return

    (1, 2, 3, 1, 2, 3, 1, 2, 3)

determined by evaluating $b in the context of each node from $a, and 
concatenating the resulting sequences of atomic values.

When combining node sequences obtained by evaluating a step in a path 
expression, however, duplicate nodes are eliminated based on node 
identity. According to the XQuery 1.0 and XPath 2.0 Data Model, atomic 
values do not have identity, which is why they are simply concatenated.

However, will

    let
      $a := (<a1/>, <a2/>, <a3/>),
      $b := (<b1/>, <b2/>, <b3/>)
    return
      $a/$b

return

    (<b1/>, <b2/>, <b3/>, <b1/>, <b2/>, <b3/>, <b1/>, <b2/>, <b3/>)

because the expression bound to $b constructs unique elements each time 
it is evaluated? Or should (<b1/>, <b2/>, <b3/>) be returned? This might 
be the case if the expression bound to $b is only evaluated once (ie 
when it is bound, before considering the "return" expression) and the 
constructed elements <b1/>, <b2/>, and <b3/> do actually have an 
identity. This raises another question: do constructed nodes even have 
an identity, or does the concept apply only to nodes from a document?

Later
Charlie

Received on Tuesday, 26 April 2005 05:16:18 UTC