intersection in XQuery

September 02, 2008 Data Platform

A recent and rather simple question.

I have two sequences, let's say 1,2,3 and 2,3,4 and I need to get the items that exist in both, in this case 2,3

One could think to use the union and intersect operators, available in XQuery. Unfortunately, these operators are based on node identity, the arguments are sequences of nodes not atomic values.

So, there were a few answers of the form $seq1[. = $seq2]
Which is ok if you don’t mind about possible duplicate values in the result.

I would consider using the FunctX XQuery library. It includes a number of set-operation functions.

There are of course many more functions in FunctX which will be handy one day or the other during your XQuery programming. And remember DataDirect XQuery has been certified with FunctX. Maybe consider to add the FunctX function library to your XQuery tools set?

Marc Van Cappellen