[xquery-talk] Removing douplicate elements
EXTERNAL Kruse Peter (Praktikant;
CR/AEA1-Si)
external.Peter.Kruse at de.bosch.com
Wed Aug 10 15:37:26 PDT 2005
Hi folks
I have an xml file with douplicate elements like this
<connect>
<a start="luigi" target="mario"/>
<b start="luigi" target="princess"/>
<a start="princess" target="mario"/>
<a start="joshi" target="luigi"/>
<a start="luigi" target="mario"/>
<b start="luigi" target="mario"/>
</connect>
I want to remove all douplicates, so my result would look like:
<connect>
<a start="luigi" target="mario"/>
<b start="luigi" target="princess"/>
<a start="princess" target="mario"/>
<a start="joshi" target="luigi"/>
<b start="luigi" target="mario"/>
</connect>
I managed to develope the following:
-------------------
declare function local:notIn($pivot as node(),$list as node()*) as
xs:boolean {
if (count($list)=0) then
true()
else
(not( deep-equal($pivot,$list[1]))
and local:notIn($pivot, $list[position()>1]) )
};
for $c at $cpos in $connections
where local:notIn($c,$connections[position()<$c])
return $c
-------------------
With small files, this works, but with larger files, i get
Error on line 20 of file:/.../connections.xq:
Too many nested function calls. May be due to infinite recursion.
Query processing failed: Run-time errors were reported
Any hints ?
Thanks a lot
Peter
More information about the talk
mailing list