Loading TOC...

MarkLogic 12 Product Documentation
xdmp:unpath

xdmp:unpath(
   $expr as xs:string,
   [$map as map:map?],
   [$context as node()?],
   [$options as (element()|map:map)?]
) 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.
options Options with which to customize this operation. You can specify options as either an options XML element in the namespace "xdmp:eval", or as a map:map. The option names below are XML localnames. When using a map, replace any hyphens in an option name with camel casing. For example, "an-option" becomes "anOption" when used as a map:map entry key. This function supports the following options:
ignore-amps
Whether or not to evaluate the code without using any Amps from the caller. Allowed values: true, false (default). If this option is set to true, the code is evaluated without using Amps from the caller. For more details, see Temporarily Increasing Privileges with Amps. This option is not usable with dbg:eval.
isolate
Whether or not to evaluate the path with the calling HTTP request, HTTP response, and session context hidden from the evaluated code. Allowed values: true, false (default). If this option is set to true, the path runs as if outside of an HTTP App Server: builtins that read the request (e.g. xdmp:get-request-header) or write the response (e.g. xdmp:add-response-header) behave as if called outside of an HTTP context, typically returning the empty sequence. Session-related builtins likewise have no session to read or update; in particular, xdmp:set-session-field returns the set value instead of creating a new session. This option is intended as a defense-in-depth control when evaluating user-supplied paths, and is typically used together with ignore-amps.

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.
  

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