Hi Marco,
case 2) applying the same operation on all element (i.e. 1,2,3,4)
Here is one solution (I bound your document to the context item and used the 'update' keyword, such that the effects of the main-memory updates will be immediately visible):
declare context item := document { <Keywords> <Record Keywords="Bus">10 20 30 40</Record> <Record Keywords="Bus">11 21 31 41</Record> </Keywords> }; . update { for $record in /Keywords/Record let $values := tokenize($record) let $updated-numbers := ( for $value in $values return number($value) * 2 ) let $new-value := string-join($updated-numbers, ' ') return replace value of node $record with $new-value }
case 1) applying the same operation on multiple elements (i.e. element 3 and 4)
I added the solution for Case 1 after the first, as it can be treated as a special-case. Moreover, I varied the user XQuery expressions a little, simply to show that there are various other solutions:
. update { for $record-text in /Keywords/Record/text() return replace node $record-text with ( for $value at $pos in tokenize($record-text) return if($pos = (3,4)) then number($value) * 2 else $value ) => string-join(' ') }
Hope this helps, Christian