Thank you very much, Christian, a tip much appreciated! It works. In case (quite improbable) that someone else faces the requirement to add namespaces, retaining the base URI, I add the code of a function I wrote for this operation. Kind regards,Hans-Jürgen PS: Is it not simply oversight that the Update spec does not support the insertion of namespace nodes, although XQuery 3.0 does define their constructors? Would a feature request have any chance? (:~ : Adds namespace nodes to a node, retaining its base URI. : Note that the namespaces are added to the root element of : the incoming document or fragment. :) declare function f:addNamespaces($node as node(), $namespaces as namespace-node()*) as node() { let $root := $node ! root() let $fnElem := function($n) {$n/descendant-or-self::*[1]} let $prefixes := $namespaces ! name(.) let $uris := $namespaces ! string(.) return $root update { for $p at $pos in $prefixes let $uri := $uris[$pos] let $attName := QName($uri, $p||':_') return insert node attribute {$attName} {()} into $fnElem(.) } update { let $elem := $fnElem(.) for $p in $prefixes return delete node $elem/@*[name() eq $p||':_'] }};
Am Montag, 4. August 2025 um 17:03:28 MESZ hat Christian Grün cg@basex.org Folgendes geschrieben:
#yiv3648432543 P {margin-top:0;margin-bottom:0;}Hi Hans-Jürgen, It feels a bit clumsy, but adding a prefixed attribute and removing it again should do the job: let $xml := doc('x.xml') let $updated := $xml update { insert node <a xmlns:prefix='URI' prefix:attr=''/>/@* into * } update { delete node */@attr } return ($updated, base-uri($updated)) Best,Christian Von: Hans-Juergen Rennau <hrennau@yahoo.de> Gesendet: Montag, 4. August 2025 13:09 An: BaseX <basex-talk@mailman.uni-konstanz.de>; Christian Grün <cg@basex.org> Betreff: Re: AW: [basex-talk] Add namespace bindings via copy/modify/return Thank you, Christian! The problem is that this way I lose the base URI! The only way how to retain it which I am aware of would be the insertion of @xml:base, but this amounts to a change of the document I may not be authorized to do by the context. Is there any way how to change a document (as modified copy, not via copy/modify/return) and retain or control the base URI of the result, without inserting @xml:base? Kind regards,Hans-Jürgen Am Montag, 4. August 2025 um 12:49:50 MESZ hat Christian Grün <cg@basex.org> Folgendes geschrieben:
Hi Hans-Jürgen, The insertion of namespace nodes has not been defined in the XQuery Update spec. You may need choose the classic element constructor for that: let $doc := <doc><a/></doc>return element { node-name($doc) } { $doc/@*, namespace xyz { 'https://basex.org/ns' }, $doc/node()} Hope this helps,ChristianVon: Hans-Juergen Rennau via BaseX-Talk <basex-talk@mailman.uni-konstanz.de> Gesendet: Samstag, 2. August 2025 15:51 An: BaseX <basex-talk@mailman.uni-konstanz.de> Betreff: [basex-talk] Add namespace bindings via copy/modify/return Dear BaseX people, I cannot use copy/modify/return in order to add a namespacing: let $doc := <doc><a/></doc>return copy $doc_ := $doc modify insert node namespace xyz {'https://basex.org/ns'} into $doc_ return $doc_ =><doc> <a/></doc> Is this a bug? Kind regards,Hans-Jürgen