Variable references in path expressions

Charles Brooking <[email protected]> Tue, 26 Apr 2005 15:16:05 +1000
Newsgroups gmane.comp.web.query-languages
Message-ID <[email protected]>
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
charles.brooking.vcf (text/x-vcard, 317 B)
begin:vcard
fn:Charles Brooking
n:Brooking;Charles
org:Canon Information Systems Research Australia Pty Ltd (CISRA);Emerging Technology Division
email;internet:[email protected]
title:Associate Software Engineer
tel;work:+612 9805 2516
url:http://www.research.canon.com.au
version:2.1
end:vcard