Loading TOC...


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


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.

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.


  => <title>Querying XML</title>


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>
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>


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.

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