Loading TOC...


   node as Node,
   element as xs.QName[],
   callback as function(NodeBuilder, node()) as xs.string?,
   builder as NodeBuilder
) as null


Returns a copy of the node, replacing any elements found with the specified expression.

node A node to run the walk over. The node must be either a document node or an element node; it cannot be a text node.
element The name of elements to replace.
callback A function to call on each match.
builder The builder that will be used to construct the modified copy.

Usage Notes

The arguments to the callback function provide context for the element match.

builder as NodeBuilder

An Node builder that is building the highlighted node copy. Whatever the callback adds to the builder will be added to the final copy.

node as element()

The matching element node.

The return from the callback function is an action that specifies what happens next:

(default) Walk the next match. If there are no more matches, return all evaluation results.
Skip walking any more matches and return all evaluation results.
Stop walking matches and return all evaluation results.
Continue with the previous action.


//  Replace every 'name' element with the text "Mary"
var x = new NodeBuilder();
x.addText("Dear ");
x.startElement("name"); x.endElement();
x.addText( ", thank you for your interest.");
var result = new NodeBuilder();
cts.elementWalk(x.toNode(), xs.QName("name"),
  function(builder,node) {
<p>Dear Mary, thank you for your interest.</p>

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