xdmp:with-namespaces( $nsbindings as (xs:string*|map:map), $expr as item()* ) as item()*
Evaluates the expression in the context of a specific set of namespace bindings.
http://marklogic.com/xdmp/privileges/xdmp-with-namespaces
(: 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"/> :)
(: 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"/> :)
(: Defining a default namespace :) xdmp:with-namespaces( ('', 'x'), <test> <test1>hello</test1> </test> => <test xmlns="x"> <test1>hello</test1> </test>
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.