xdmp:unpath

xdmp:unpath(
   $expr as xs:string,
   [$map as map:map?],
   [$context as node()?]
) as item()*

Summary

Evaluate a string as an XPath and return the corresponding node(s). Any value that is the result of xdmp:path is a valid input to xdmp:unpath. Any invalid inputs throw an XDMP-UNPATH exception. To evaluate non-XPath expressions, use xdmp:value.

Parameters
expr The XPath expression string to evaluate. The XPath expression must be of the form returned by xdmp:path.
map A map of namespace bindings. The keys should be namespace prefixes and the values should be namespace URIs. These namespace bindings will be added to the in-scope namespace bindings in the evaluation of the path.
context Bind the context node to this value during evaluation of the expression.

Example

  xdmp:unpath("/bookstore/book/title")
  => <title>Querying XML</title>
  

Example

The following example shows how you can use xdmp:unpath and specify namespace bindings that are not in the current query scope.

xquery version "1.0-ml";

let $doc := <html xmlns="http://www.w3.org/1999/xhtml">
              <body><p>This is a document</p></body>
            </html>
let $namespaces := map:map()
let $_ := map:put($namespaces, "xh", "http://www.w3.org/1999/xhtml")
let $xpath-str := "$doc/xh:body/xh:p"
return xdmp:unpath($xpath-str, $namespaces)

=> <p xmlns="http://www.w3.org/1999/xhtml">This is a document</p>
  

Example

The following example shows how to use the context node.

xquery version "1.0-ml";

let $doc := <html xmlns="http://www.w3.org/1999/xhtml">
              <body><p>This is a document</p></body>
            </html>
let $namespaces := map:map()
let $_ := map:put($namespaces, "xh", "http://www.w3.org/1999/xhtml")
let $xpath-str := "/xh:body/xh:p"
return xdmp:unpath($xpath-str, $namespaces, $doc)

=> <p xmlns="http://www.w3.org/1999/xhtml">This is a document</p>
  

Example

The following example shows that xdmp:unpath will throw an error if the specified XPath expression would never be returned by xdmp:path.

  xdmp:unpath("/bookstore/book/title[@name eq 'Querying XML']")
  => throws the XDMP-UNPATH exception, because the specified
     path expression would never be the output of xdmp:path.
  
Powered by MarkLogic Server | Terms of Use | Privacy Policy