Gary, Thanks for your response.
Regards, Nachi From: [email protected] [mailto:[email protected]] On Behalf Of Gary Vidal Sent: Friday, December 13, 2013 6:19 AM To: [email protected] Subject: Re: [MarkLogic Dev General] deleteing duplicate elements from XMLs in Marklogic Nikin, A very simple way 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/> **************** CAUTION - Disclaimer ***************** This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely for the use of the addressee(s). If you are not the intended recipient, please notify the sender by e-mail and delete the original message. Further, you are not to copy, disclose, or distribute this e-mail or its contents to any other person and any such actions are unlawful. This e-mail may contain viruses. Infosys has taken every reasonable precaution to minimize this risk, but is not liable for any damage you may sustain as a result of any virus in this e-mail. You should carry out your own virus checks before opening the e-mail or attachment. Infosys reserves the right to monitor and review the content of all messages sent to or from this e-mail address. Messages sent to or from this e-mail address may be stored on the Infosys e-mail system. ***INFOSYS******** End of Disclaimer ********INFOSYS***
_______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
