The mistake in your code is that you search for each (distinct) value separately. As suggested by Phil, you should do a combined search for all values in one XPath. If you drop the for
line, and replace the let $def
with an expression that searches all values, you'll be there. Something like:
let $allitems := $src/itemset/item
let $C:=distinct-values($allitems)
let $def:=$src/itemset[item=$C]
return $def
You can replace $C here by any sequence of values, for instance:
let $C := ('milk', 'paper')
The =
operator is capable of comparing sequences and node-sets, effectively doing an intersect. It returns true if the intersect isn't empty.
HTH!