Loading TOC...

MarkLogic 12 EA 2 Product Documentation
xdmp:node-insert-before

xdmp:node-insert-before(
   $sibling as node(),
   $new as node()
) as empty-sequence()

Summary

Adds an immediately preceding sibling to a node.

Parameters
sibling The sibling node to be preceded by the new node.
new The new node to be inserted.

Usage Notes

Attribute nodes cannot be preceded by non-attribute nodes. Non-attribute nodes cannot be preceded by attribute nodes. Element nodes cannot have document node children. Document nodes cannot have multiple roots. On-the-fly constructed nodes cannot be updated.

Example

(: create a document :)
xdmp:document-insert("/example.xml",
    <a><b>bbb</b></a>);

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

(: look at the new document :)
fn:doc("/example.xml")
 =>
<?xml version="1.0" encoding="UTF-8"?>
<a><c>ccc</c><b>bbb</b></a>

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