The set command


set name = expression set . = expression

The first form binds a variable to the value of the expression. The variable name may be written as a simple NCName, or as a lexical QName, or as an EQName in Q{uri}local format; it may also be preceded by a "$" sign (which is ignored).

The variable may be used in XPath expressions and queries appearing later in the script.

The second form:

set . = expression

may be used to set the current document. In this case the expression must evaluate to a single document node. For example:

set . = doc('books.xml')

achieves the same effect as:

load books.xml

Note that all updating commands (such as delete, rename etc.) create a new copy of the current document. Variables that were set before the updating command continue to reference the document in the state it was in before the update.