Hi Markus,
I don't think the messages are misleading, however the rules here can be hard to follow at first.
My understanding of the updating rules is:
All the updating must be done together as the very last thing to happen.
This means ONLY in the final 'return' statement of the main expression or
defined in the final 'return' statement in functions.
These updating function definitions can only be called in the final statement of the main expression.
The other XQuery
rule
that applies to your examples is that:
if there is only one expression in main or a function body then the keyword "return" is omitted
So your first example becomes:
declare %updating function local:add_document($items as item()*)
as empty-sequence()
{
db:add("Test_DB", $items, "Test.xml")
};
let $my_data as element() := <root><contents>My document</contents></root>
return local:add_document($my_data)
In your second example, you can define the updating function with let, but calling it requires the use of the updating keyword as described in the link you give.
let $my_data as element() := <root><contents>My document</contents></root>,
$add_document := %updating function($items) {db:add("Test_DB", $items, "Test.xml")}
return (updating $add_document($my_data))
Regards
/Andy