I found the following XQuery user-defined function in the O'Reiily book XQuery and it is used to change the namespace of an XML file when it is printed:
declare namespace functx = "http://www.functx.com";
declare function functx:change-element-ns-deep
($element as element(), $newns as xs:string) as element()
{
let $newName := QName ($newns, name ($element))
return (element {$newName}
{$element/@*,
for $child in $element/node()
return if ($child instance of element())
then functx:change-element-ns-deep ($child, $newns)
else $child
}
)
};
One example to call this function with is:
<text xmlns:pre="pre">
{
functx:change-element-ns-deep(<pre:x><pre:y>123</pre:y></pre:x>, "http://new")
}
</text>
returns:
<test xmlns:pre="pre" >
< x xmlns="http//new">
<y>123</y>
</x>
</test>
But what I've got is:
<test>
<x>
<y>123</y>
</x>
</test>
It appears that the original namespace is stripped but the new one has yet to be attached or is it simply that the processor doesn't print the namespace because the unaffected namespace declaration is also gone?