Geert, Sorry for the typo. I have made the correction in line 6.
declare namespace functx = "http://www.functx.com"; declare function functx:is-node-in-sequence ( $var2ode as node()? , $seq as node()* ) as xs:boolean { some $var2odeInSeq in $seq satisfies $var2odeInSeq is $var2ode } ; 1. for $var1 in doc("/abc.xml")//b 2. let $count := fn:count($var1/c) 3. for $var2 in 1 to $count 4. where ($count > 1 and fn:not(($var2 + 1) >= $count)) 5. return for $var3 in ($var2 + 1) to $count 6. where functx:is-node-in-sequence($m/c [$var3], $m/c) 7. return xdmp:node-delete($m/c [$var3]) I will go with the approach suggested by Gary. It seems I can avoid conflicting updates by making use of a map. Regards, Nachiketa From: [email protected] [mailto:[email protected]] On Behalf Of Geert Josten Sent: Thursday, December 12, 2013 9:14 PM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] deleteing duplicate elements from XMLs in Marklogic Hi Nachiketa, The conflicting updates means you are updating/deleting the same node multiple times. So, the approach isn't necessarily bad, but there do is a logical error in your code. Could be a copy/paste error, but you are iterating over doc()//b, but deleting $m/citation? You are also using positional indexing. Why not simply iterate over the nodes themselves? That is usually much more convenient. Apart from this, the approach to use map:map as suggested by Gary is likely to be one of the fastest solutions. Whether doing a doc-insert or individual node updates is fastest depends, but if you are already touching most of the XML this way, then doing a full update is likely equally fast. Perhaps even faster.. Cheers, Geert Van: [email protected]<http://ogic.com> [mailto:[email protected]<mailto:[email protected]>] Namens Nachiketa Kulkarni Verzonden: donderdag 12 december 2013 14:34 Aan: [email protected]<mailto:[email protected]> Onderwerp: [MarkLogic Dev General] deleteing duplicate elements from XMLs in Marklogic Hi, I have an xml in the below form: <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> I want to retain the <c> elements with unique @href. The duplicate entries should be removed. Thus, the output should be: <a> <b> <c href="input1"/> <c href="input2"/> <c href="input3"/> </b> <b> <c href="input1"/> <c href="input2"/> </b> </a> I have written the below xquery for the same: declare namespace functx = "http://www.functx.com"; declare function functx:is-node-in-sequence ( $var2ode as node()? , $seq as node()* ) as xs:boolean { some $var2odeInSeq in $seq satisfies $var2odeInSeq is $var2ode } ; for $var1 in doc("/abc.xml")//b let $count := fn:count($var1/c) for $var2 in 1 to $count where ($count > 1 and fn:not(($var2 + 1) >= $count)) return for $var3 in ($var2 + 1) to $count where functx:is-node-in-sequence($m/citation[$var3], $m/citation) return xdmp:node-delete($m/c [$var3]) But, I am getting xdmp:conflictingupdates exception. Please suggest an alternative to get the desired output. Regards, Nachiketa Kulkarni **************** 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
