Nikin,
A very simple wat dedupe is to use maps. The important thing is to clear the
map after each parent traversal to ensure each subchild of b is unique not
unique across entire document.
And also when updating nodes in MarkLogic it is important that you not try to
update/delete a child node of a parent node who is also updated. So it is
better to traverse the whole document or a portion of the document such that
your updates constitutes a single update within the document. This will help
avoid conflicting updates.
[Query Console]
xquery version "1.0-ml";
declare namespace local = "urn:local";
declare option xdmp:mapping "false";
declare function local:prune-unique(
$context,
$push-map
) {
if($context/@href)
then if(map:get($push-map,fn:normalize-space($context/@href))) then () else
(map:put($push-map,fn:normalize-space($context/@href),$context),$context)
else if($context/element())
then element {fn:node-name($context)} {
$context/@*,
for $node in $context/element()
return local:prune-unique($node,$push-map),
map:clear($push-map)
}
else $context
};
let $nodes :=
<a>
<b>
<c href="input1"/>
<c href="input2"/>
<c href="input1"/>
<c href="input1"/>
<c href="input1"/>
<c href="input3"/>
<c href="input3"/>
<c href="input1"/>
<c href="input1"/>
<c href="input1"/>
</b>
<b>
<c href="input1"/>
<c href="input2"/>
<c href="input1"/>
<c href="input1"/>
<c href="input1"/>
</b>
</a>
return
(:Assuming $nodes is pulled from database:)
xdmp:node-replace($nodes,local:prune-unique($nodes,map:map()))
returns
<a>
<b>
<c href="input1"/>
<c href="input2"/>
<c href="input3"/>
</b>
<b>
<c href="input1"/>
<c href="input2"/>
</b>
</a>
Gary Vidal
Media Consultant
MarkLogic Corporation
[email protected]<mailto:[email protected]>
Phone: +1 917 576-5794
Skype: ml-garyvidal
www.marklogic.com<http://www.marklogic.com/>
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general