Many thanks. I was focused on the "with $v[$i]" part and I forgot to check that I get a single element each time. Indeed, I have two value elements for some of them. It comes from another XML document in the DB that I used for testing purposes and completely forgot to remove.

On 02 May 2013, at 10:59, Dirk Kirsten wrote:

Dear Ludovic,

The error message indicates that the XPath /datas[@site=$site]/data[num=$x]/value return not just a single element, but multiple instead. Could it be that for some values of @site and @num you have multiple datas. This would explain why it sometimes happens and sometimes it does not.
It is hard to tell as we don't have the whole xml data file, but just a snippet. Maybe you could test this and instead of updating your XML simply output /datas[@site=$site]/data[num=$x]/value
You can then check if you have multiple values and then maybe you want to change your xml (if this should be invalid) or you have to change your XQuery (you could do a FLOWR expression to update all data nodes).

Cheers,
Dirk