xdmp:unpath( $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
.
xdmp:unpath("/bookstore/book/title") => <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> </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>
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.