Loading TOC...

MarkLogic 12 EA 2 Product Documentation
temporal:node-replace

temporal:node-replace(
   $temporal-collection as xs:string,
   $old as node(),
   $new as node(),
   [$temporal-doc-uri as xs:string]
) as empty-sequence()

Summary

Replaces a node in a temporal document.

Parameters
temporal-collection The URI for the protected temporal collection in which the document is to belong. This must have been previously created by the temporal:collection-create function. All versions of the temporal document will be associated with this temporal collection.
old The old node, to be replaced.
new The new node.
temporal-doc-uri The URI of the temporal document to be updated.

Usage Notes

The forth argument "temporal-doc-uri" is not required for documents inserted with MarkLogic 9.0 version of temporal:document-insert or later.

Attribute nodes cannot be replaced by non-attribute nodes. Non-attribute nodes cannot be replaced by attribute nodes. Element nodes cannot have document node children. Document nodes cannot have multiple roots.

If the caller of the function uses function mapping and $old is an empty sequence, the node-replace function may return an empty sequence. It will not return an error.

Example

 
xquery version "1.0-ml"; 
 
import module namespace temporal = "http://marklogic.com/xdmp/temporal" 
      at "/MarkLogic/temporal.xqy";

(: create a document :)
let $options :=  
<options xmlns="xdmp:document-insert">
    <metadata>
       <map:map xmlns:map="http://marklogic.com/xdmp/map">
         <map:entry key="validStart">
           <map:value>2014-04-03T11:00:00</map:value>
         </map:entry>
         <map:entry key="validEnd">
           <map:value>2014-04-03T16:00:00</map:value>
         </map:entry> 
       </map:map>
    </metadata> 
</options> 
return 
temporal:document-insert("kool","/example.xml",
    <a><b>bbb</b></a>, $options);

(: add a c node before the b node :)
temporal:node-replace("kool", fn:doc("/example.xml")/a/b,
    <c>ccc</c>);

(: look at the new document :)
fn:doc("/example.xml")
 

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.