[xquery-talk] Deep-equal between sequences

Ronald Bourret rpbourret at rpbourret.com
Wed Jul 11 00:38:54 PDT 2007


I have two sequences that I would like to compare. The sequences are 
composed of elements and the comparison is true if any member of the 
first sequence is deep-equal to any member of the second sequence. 
(Essentially, I want to do an = operation, but using deep-equal rather 
than atomic equality.)

Can anybody think of a way to do this comparison with the = operator? 
This would give the query engine the chance to optimize the comparison, 
or at least to end the comparison early if a match was found. The 
problem is somewhat simplified by the fact that the definition of the 
elements is <!ELEMENT A (A1, A2)>.

Note that the following is not sufficient:

    let $firstSeq := ...
    let $secondSeq := ...
       if (($firstSeq/A1 = $secondSeq/A1) and
           ($firstSeq/A2 = $secondSeq/A2)
       then fn:true()
       else fn:false()

The problem with this is that it returns true if any pairs of A1 and A2 
match, while I require that an A1 and A2 with the same parent in the 
first sequence match an A1 and A2 with the same parent in the second 

Barring use of the = operator, is there a simple solution to this 
problem that would allow the engine to stop processing on the first 
match, rather than performing n x m deep-equal comparisons and searching 
the resulting sequence for an instance of true?

Thanks in advance,

-- Ron

More information about the talk mailing list