Loading TOC...

MarkLogic 9 Product Documentation
Node.xpath

Node.xpath(
   path as String,
   [bindings as Object]
) as Sequence

Summary

Evaluate an XPath using the node as context.

Parameters
path The XPath to evaluate.
bindings Namespace bindings to use to interpret the XPath. The key is the prefix and the value is the namespace URI.

Required Privileges

http://marklogic.com/xdmp/privileges/xdmp-value

Usage Notes

The path is evaluated in the context of the current node, but it may be any valid XPath. Rooted paths will be confined to the current document, but they will not be confined to the subtree rooted at the current node. For example, the node.xpath("/title") will return the node <title>Here</title> regardless of which child of the following document the xpath method is called on:

<article>
  <title>Here</title>
  <subsection>
     <title>Subtitle</title>
     More stuff
  </subsection>
</article>

To get the subtitle of the subsection element, one would need to use the path ./title from the subsection element node.

Valid XPaths include more than just path expressions: arithmetic expressions, function calls, and so on are valid as well.

Example

const node = fn.head(cts.search("example"));
node.xpath("ex:section/ex:title", {"ex":"http://example.com/ns"})

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