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, Christian ________________________________ Von: 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