Help! Does the node comparison work this way?

Hi all,
I’m learning XQuery now and I have a question:
Given a sequence of non-distinct nodes(what I say for “non-distinct” is that there might be nodes with the same node name and value, ie. abc), can we use the node comparison predicates(is, <<, >>) to identify them? E.g. given a sequence $seq, waht can we get from the following XQuery piece?

for $e1 in $seq
let $other :=
(
for $e2 in $seq
return
(
if (not($e1 is $e2)) then $e2 else ()
)
)

Suppose we have a node sequence <a,b,d,c,a>, what can we get in $other for the first node “a” after this query is executed? Do we get {b,d,c} or {b,d,c,a}? If it’s {b,d,c}, then is there any other way to get {b,d,c,a} instead?

Thank you very much. Your help is really appreciated.

Hi,

for


let $seq :=(<a/>,<b/>,<c/>,<a/>) 
for $e1 in $seq 
let $other := 
( 
for $e2 in $seq 
return 
( 
if (not($e1 is $e2)) then $e2 else () 
) 
) 
return <other>{$other}</other>

your get the result


<other>
  <b /> 
  <c /> 
  <a /> 
  </other>
- <other>
  <a /> 
  <c /> 
  <a /> 
  </other>
- <other>
  <a /> 
  <b /> 
  <a /> 
  </other>
- <other>
  <a /> 
  <b /> 
  <c /> 
  </other>

because the operator “is” works on identity, not on equality.

The operators << and >> are defined even for non-tree situations (as in the example sequence above), but their result is implementation dependent, so it is not a good idea to use them in this scenario.

Regards

Harald