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] [mailto:
[email protected]] *Namens *Nachiketa Kulkarni
*Verzonden:* donderdag 12 december 2013 14:34
*Aan:* [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

Reply via email to