[xquery-talk] Removing douplicate elements
Martin Probst
martin at x-hive.com
Wed Aug 10 19:17:27 PDT 2005
Hi,
your function is recursive relative to the number of elements. As your
processor obviously does not have tail call optimization, the
(processors) recursion level is dependent on the number of elements, and
to prevent a StackOverFlowException (or sth worse with C) the processor
seems to have a built in limit.
The solution is to have a non recursive function.
declare function local:notIn($pivot as node(),$list as node()*) as
xs:boolean {
if ( for $elem at $index in $list
return
if ( deep-equal($pivot, $elem) )
then true()
else ()
) then true()
else false()
}
The trick is to return a list of boolean values, but only return a true
value if the node is deep-equal, otherwise return nothing. The outer if
will try to evaluate the EBV of the condition and receive an empty
sequence (--> false) if none of the elements was deep-equal, a list
starting with the value true otherwise.
You just need the outer if to make sure it's exactly one boolean btw.
Martin
More information about the talk
mailing list