Reputation: 745
Having two different list in XQuery
$list1:
A
B
C
D
and
$list2
A
D
Is there a function that does: create $list3 with all element of $list2 not present in $list1?
Upvotes: 2
Views: 723
Reputation: 4241
If your values are atomic, you can exploit the existential semantics of =
:
let $list1 := ('A', 'B', 'C', 'D')
let $list2 := ('A', 'D', 'E', 'F')
let $list3 := $list2[not(. = $list1)]
return $list3
Result: 'E', 'F'
If you want to compare XML nodes by node identity, you can use the except
keyword instead:
let $nodes := (<A/>, <B/>, <C/>, <D/>, <E/>, <F/>)
let $list1 := ($nodes[1], $nodes[2], $nodes[3], $nodes[4])
let $list2 := ($nodes[1], $nodes[4], $nodes[5], $nodes[6])
let $list3 := $list2 except $list1
return $list3
Result: <E/>, <F/>
Upvotes: 4