Loading TOC...

xdmp:with-namespaces

xdmp:with-namespaces(
   $nsbindings as (xs:string*|map:map),
   $expr as item()*
) as item()*

Summary

Evaluates the expression in the context of a specific set of namespace bindings.

Parameters
nsbindings A set of namespace prefix bindings, expressed as either a sequence of alternating (prefix,uri) pairs, or a map:map where the keys are prefixes and the values are namespace URIs. If the prefix is the empty string, the following URI becomes the default namespace of the resulting item(s).
expr An expression to evaluate in the context of the given namespace bindings.

Required Privileges

http://marklogic.com/xdmp/privileges/xdmp-with-namespaces

Example

(: Using a sequence of prefix-URI pairs to define the bindings :)
let $version := "1.2" return
xdmp:with-namespaces(("p", fn:concat("http://marklogic.com/p/",$version)),
   <p:bar/>
)

(: Returns: <p:bar xmlns:p="http://marklogic.com/p/1.2"/> :)

Example

(: Using a map:map to define the bindings :)
let $version := "1.2" 
return xdmp:with-namespaces(
  map:map() => map:with("p", fn:concat("http://marklogic.com/p/",$version)),
  <p:bar/>
)

(: Returns: <p:bar xmlns:p="http://marklogic.com/p/1.2"/> :)

Example

(: Defining a default namespace :)
xdmp:with-namespaces(
   ('', 'x'),
   <test>
      <test1>hello</test1>
   </test>
=>
<test xmlns="x">
  <test1>hello</test1>
</test>

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