Non-updating Expressions: copy/modify/return. Multiple for-clauses inside modify
Friday, 29 April 2016 · 3 messages
GD
Günter Dunz-Wolff29 Apr 2016 13:16 #
Hi all, hi Christian,
for my queries I have to modify some legacy xml-documents. The copy/modify/return-expression works fine with one for-clause. But I have to modify different elements. I can't figure out, how to chain the for-clauses.
Working Example:
copy $doc := $document
modify (
let $first_elements := $doc//element-name
for $element in $first_elements
let $target := $element/@target
let $htm_anchor := substring-after($target, '#')
return
replace value of node $element/@target with 'xyz' || $htm_anchor
)
return
$docThis is working for one for-clause. But I have to do a lot more with different elements for example:
let $second_element := $doc//element-name-second
for $ele in $second_elements
let $...
return ...The returning document should contain all modifications. How can I chain the for-clauses inside modify?
Thanks for a hint in advance.
Günter
CG
Christian Grün29 Apr 2016 13:39 #
Hi Günter,
The chaining of update operations just got easier with the extension of our "update" operator [1,2]. I’d be interested in your feedback.
Cheers,
Christian
[1] http://docs.basex.org/wiki/XQuery_Update#update
[2] http://files.basex.org/releases/latest/
Quoted text · Günter Dunz-Wolff · 32 lines
On Fri, Apr 29, 2016 at 1:16 PM, Günter Dunz-Wolff <kleist at mail.dunzwolff.de> wrote: > Hi all, hi Christian, > > for my queries I have to modify some legacy xml-documents. The copy/modify/return-expression works fine with one for-clause. But I have to modify different elements. I can't figure out, how to chain the for-clauses. > > Working Example: > > copy $doc := $document > modify ( > let $first_elements := $doc//element-name > for $element in $first_elements > let $target := $element/@target > let $htm_anchor := substring-after($target, '#') > return > replace value of node $element/@target with 'xyz' || $htm_anchor > ) > return > $doc > > This is working for one for-clause. But I have to do a lot more with different elements for example: > > let $second_element := $doc//element-name-second > for $ele in $second_elements > let $... > return ... > > The returning document should contain all modifications. How can I chain the for-clauses inside modify? > > Thanks for a hint in advance. > > Günter
GD
Günter Dunz-Wolff29 Apr 2016 17:24 #
Hi Christian,
thanks for the hint. I'll try it after updating my system. Looks promising.
Cheers, Günter
Quoted text · Christian Grün · 47 lines
> Am 29.04.2016 um 13:39 schrieb Christian Grün <christian.gruen at gmail.com>: > > Hi Günter, > > The chaining of update operations just got easier with the extension > of our "update" operator [1,2]. I’d be interested in your feedback. > > Cheers, > Christian > > [1] http://docs.basex.org/wiki/XQuery_Update#update > [2] http://files.basex.org/releases/latest/ > > > On Fri, Apr 29, 2016 at 1:16 PM, Günter Dunz-Wolff > <kleist at mail.dunzwolff.de> wrote: >> Hi all, hi Christian, >> >> for my queries I have to modify some legacy xml-documents. The copy/modify/return-expression works fine with one for-clause. But I have to modify different elements. I can't figure out, how to chain the for-clauses. >> >> Working Example: >> >> copy $doc := $document >> modify ( >> let $first_elements := $doc//element-name >> for $element in $first_elements >> let $target := $element/@target >> let $htm_anchor := substring-after($target, '#') >> return >> replace value of node $element/@target with 'xyz' || $htm_anchor >> ) >> return >> $doc >> >> This is working for one for-clause. But I have to do a lot more with different elements for example: >> >> let $second_element := $doc//element-name-second >> for $ele in $second_elements >> let $... >> return ... >> >> The returning document should contain all modifications. How can I chain the for-clauses inside modify? >> >> Thanks for a hint in advance. >> >> Günter >
Written for BaseX 8.4. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery