Previous versions of e Xist already offered some functions to execute XUpdate queries from within XQuery.

However, this approach had its limitations, mainly due to the lack of integration between the XUpdate language and XQuery.

xquery no updating expression allowed-18

An update statement may occur at any position within the XQuery main code or a function body.

When using an update within the return clause of a FLWOR expression, it should be clear that one should not delete or replace nodes that are still being used by enclosing code.

If the selection expression selects a node that has no parent, then the result is to delete the entire document from the container.

When replacing elements, the selection expression used to select the target must be non-updating, and it must not result in an empty set.

XUpdate operations are specified in XML and the XUpdate processor uses its own instance of the query engine.

To forward information from the XQuery to the XUpdate, one had to dynamically construct an XUpdate XML fragment, passing the required XPath expressions as strings.

Selection results must consist of a single element, text, comment or processing instruction.

In addition, the selection expression must not select a node without a parent node.

For this reason, if the formatting of your XML documents are very important to you, you should avoid using XQuery Update Statements on your documents.