<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/cts.elementWalk.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>cts.elementWalk</api:function-name><api:suggest>cts.elementwalk</api:suggest><api:suggest>cts</api:suggest><api:suggest>elementwalk</api:suggest><api:function mode="javascript" name="elementWalk" type="builtin" lib="cts" category="SearchBuiltins" subcategory="Search" class="javascript" hidden="false" bucket="MarkLogic Built-In Functions" prefix="cts" namespace="http://marklogic.com/cts" fullname="cts.elementWalk"><api:summary>
  Returns a copy of the node, replacing any elements found
  with the specified expression.
</api:summary><api:params><api:param name="node" type="node()"><api:param-description>
    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.
  </api:param-description><api:param-name>node</api:param-name><api:param-type>Node</api:param-type></api:param><api:param name="element" type="xs:QName*"><api:param-description>
    The name of elements to replace.
  </api:param-description><api:param-name>element</api:param-name><api:param-type>xs.QName[]</api:param-type></api:param><api:param name="callback" type="function(NodeBuilder, node()) as xs:string?"><api:param-description>
    A function to call on each match.
  </api:param-description><api:param-name>callback</api:param-name><api:param-type>function(NodeBuilder, node()) as xs.string?</api:param-type></api:param><api:param name="builder" type="NodeBuilder"><api:param-description>
    The builder that will be used to construct the modified copy.
  </api:param-description><api:param-name>builder</api:param-name><api:param-type>NodeBuilder</api:param-type></api:param></api:params><api:return>null</api:return><api:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">
    The arguments to the callback function provide context for the element match.
  </p>
  <blockquote xmlns="http://www.w3.org/1999/xhtml"><dl>
    <dt><code>builder</code> as <code>NodeBuilder</code></dt>
    <dd><p>An Node builder that is building the highlighted node copy. 
    Whetever the callback adds to the builder will be added to the final copy.
    </p></dd>
    <dt><code>node</code> as <code>element()</code></dt>
    <dd><p>The matching element node.</p></dd>
 </dl></blockquote>
 <p xmlns="http://www.w3.org/1999/xhtml">The return from the callback function is an action that specifies what happens next:</p>
    <dl xmlns="http://www.w3.org/1999/xhtml">
      <dt>"continue"</dt>
      <dd>(default) Walk the next match.
      If there are no more matches, return all evaluation results.</dd>
      <dt>"skip"</dt>
      <dd>Skip walking any more matches and return all evaluation results.</dd>
      <dt>"break"</dt>
      <dd>Stop walking matches and return all evaluation results.</dd>
      <dt>null</dt>
      <dd>Continue with the previous action.</dd>
    </dl>
</api:usage><api:example><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
//
//  Replace every 'name' element with the text "Mary"
//
var x = new NodeBuilder();
x.startElement("p"); 
x.addText("Dear ");
x.startElement("name"); x.endElement();
x.addText( ", thank you for your interest.");
x.endElement();
var result = new NodeBuilder();
cts.elementWalk(x.toNode(), xs.QName("name"), 
  function(builder,node) {
    builder.addText("Mary")
  },
  result
);
result.toNode()
=&gt;
&lt;p&gt;Dear Mary, thank you for your interest.&lt;/p&gt;
</pre></api:example></api:function></api:function-page>