Reputation: 481
I am using BaseX latest version 11.0 beta.
I am trying to remove Texas cities in the /root/base/r
sequence by using /root/remove/r
sequence.
The goal is to use XQuery except
expression.
Here is my XML and XQuery
declare context item := document {
<root>
<base>
<r>Miami</r>
<r>Orlando</r>
<r>Dallas</r>
<r>Austin</r>
</base>
<remove>
<r>Dallas</r>
<r>Austin</r>
</remove>
</root>
};
let $remove := /root/remove/r
return /root/base/r except $remove
Desired output
<r>Miami</r>
<r>Orlando</r>
Unfortunately, I am getting the same initial XML
<r>Miami</r>
<r>Orlando</r>
<r>Dallas</r>
<r>Austin</r>
It is not clear what I am doing wrong.
Upvotes: 1
Views: 81
Reputation: 6229
With except
, the node references are compared, not their contents. For example, the following query will exclude nodes with the same node identity from the result:
let $remove := /root/base/r[position() > 2]
return /root/base/r except $remove
If you want to exclude all nodes of the base
branch that have the string values of the nodes of the $remove
branch, you can do this:
let $remove := /root/remove/r
return /root/base/r[not(. = $remove)]
Upvotes: 2
Reputation: 163595
The except
operator compares nodes by node identity, not by string value.
You want
/root/base/r[not(. = /root/base/remove)]
Upvotes: 0