Reputation: 477
Returning to XQuery after a long hiatus.
let $root := <a:b xmlns:a="ans" xmlns:c="cns"/>
for $prefix in in-scope-prefixes($root)[not(. = ('xml', 'xsi'))]
return
namespace-uri-for-prefix($prefix,$root) !
<param name="{$prefix}" value="{.}"/>
gives the expected
<param name="a" value="ans"/>
<param name="c" value="cns"/>
But if I try to wrap an element around that output like below nothing is returned
<parameters>{
let $root := <a:b xmlns:a="ans" xmlns:c="cns"/>
for $prefix in in-scope-prefixes($root)[not(. = ('xml', 'xsi'))]
return
namespace-uri-for-prefix($prefix,$root) !
<param name="{$prefix}" value="{.}"/>
}</parameters>
So what is wrong and how do I wrap the output in a parameters element?
Upvotes: 1
Views: 139
Reputation: 66723
Try letting a variable with the sequence of <param>
elements, and return the <parameters>
element referencing that variable instead of putting the FLWOR inline.
You shouldn't have to do that. I was able to generate the desired output in MarkLogic with your original code, but it seems necessary for eXist to generate the desired output.
xquery version "3.0" encoding "UTF-8";
let $root := <a:b xmlns:a="ans" xmlns:c="cns"></a:b>
let $params :=
for $prefix in in-scope-prefixes($root)[not(. = ('xml', 'xsi'))]
return
namespace-uri-for-prefix($prefix,$root) !
<param name="{$prefix}" value="{.}"/>
return
<parameters>{ $params }</parameters>
Upvotes: 3