On 09.09.2019 20:30, Andreas Mixich wrote:
Hi,
copy $c := <lorem>ipsum dolor sit amet</lorem> modify insert node namespace {"lipsum"} {"lorem-ipsum"} into $c return $c
Expected result:
<lipsum:lorem xmlns:lipsum="lorem-ipsum">ipsum dolor sit amet</lipsum:lorem>
The namespace is part of the name of a node so you need to rename the node(s) in a namespace if you want to change the namespace, see https://www.w3.org/TR/xquery-update/#id-rename saying
The effects of a rename expression are limited to its target node. Attributes and descendants of the target node are not affected. If a global change of names or namespaces is intended, some form of explicit iteration must be used. The following example illustrates such a global change. The example operates on the node bound to variable $root and all its attributes and descendants, changing all QNames with the prefix abc to have a new prefix xyz and a new namespace URI http://xyz/ns.
for $node in $root//abc:* let $localName := fn:local-name($node), $newQName := fn:concat("xyz:", $localName) return ( rename node $node as fn:QName("http://xyz/ns", $newQName), for $attr in $node/@abc:* let $attrLocalName := fn:local-name($attr), $attrNewQName := fn:concat("xyz:", $attrLocalName) return rename node $attr as fn:QName("http://xyz/ns", $attrNewQName) )