Hi Gerrit,
the return clause of the transform (copy) expression does not allow update operations. What you can do is to wrap your code in a FLWOR expression:
let $doc := copy $doc := parse-xml($wrapper) modify ( for $n in $doc/descendant-or-self::*[starts-with(local-name(), '_____')] let $repl := replace(local-name($n), '^_____', ''), $uri := namespace-uri($n) return rename node $n as QName($uri, $repl) ) return $doc return replace node db:open($doc/*:frag/@db, $doc/*:frag/@doc)//*[path() eq $doc/*:frag/@xpath] with $doc/*:frag/*
You can also use the (for now BaseX-specific) "update" keyword, e. g. as follows:
let $doc := parse-xml($wrapper) update ( for $n in descendant-or-self::*[starts-with(local-name(), '_____')] let $repl := replace(local-name($n), '^_____', ''), $uri := namespace-uri($n) return rename node $n as QName($uri, $repl) ) return replace node db:open($doc/*:frag/@db, $doc/*:frag/@doc)//*[path() eq $doc/*:frag/@xpath] with $doc/*:frag/*
Hope this helps, Christian