Question

I'm trying to update an attribute value of a node and return its previous value all in one query and I can't find a way to do it. I'm using BaseX as my XML/XQuery database.

For now I've tried doing this:

/Root/Elem/properties/property[@id='17']/@format,
replace value of node /Root/Elem/properties/property[@id='17']/@format with 'URL'

and also this:

for $prop in /Root/Elem/properties/property[@id='17']
    let $format := $prop/@format
    return (replace value of node $prop/@format with 'URL', $format)

And multiple other tests but they all lead to the following error:

List expression: no updating expression allowed.

Is it a limitation of BaseX or is it not possible in XQuery?

Was it helpful?

Solution

XQuery Update does not allow returning results from an updating query. You can however use BaseX's proprietary update:output($seq) function to do that:

for $prop in /Root/Elem/properties/property[@id='17']
let $format := $prop/@format
return (replace value of node $format with 'URL', update:output($format))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top