Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If possible, insert the document into the database, and in a separate transaction update the nodes using <code>xdmp:node-replace</code>.</p> <pre><code>xquery version "1.0-ml"; ... xdmp:document-insert('file.xml', $file) ; xquery version "1.0-ml"; for $currentNode in doc('file.xml')//ID return xdmp:node-replace($currentNode, element ID{ concat($subject, "-", $currentNode) }); </code></pre> <p>Alternatively, if you have to update the document in memory, it is probably more optimal walking the tree only once (making your updates all in that operation), rather than multiple <code>mem:replace</code> operations (which probably each re-walk the tree).</p> <pre><code>declare function local:update-ids( $n as item(), $subject as xs:string ) as item() { typeswitch ($n) case element(ID) return element ID { concat($subject, "-", $n) } case element() return element { node-name($n) } { @*, $n/node()/local:update-ids(., $subject) } default return $n }; let $xml := xdmp:unquote($file) let $xml-with-updated-ids := local:update-ids($xml, $subject) ... </code></pre> <p><strong>Update:</strong></p> <p>As Erik suggests in the comments, you can also write the logic of <code>local:update-ids</code> in XSLT (using <code>xdmp:xslt-eval</code> or <code>xdmp:xslt-invoke</code> to execute), and they should be roughly equivalent in terms of performance. In fact, MarkLogic has a really well written blog entry on the subject: </p> <p><a href="http://developer.marklogic.com/blog/tired-of-typeswitch" rel="nofollow">http://developer.marklogic.com/blog/tired-of-typeswitch</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload