4 Extensions to the Prolog

4.1 Revalidation Declaration

[8]    Setter    ::=    BoundarySpaceDecl | DefaultCollationDecl | BaseURIDecl | ConstructionDecl | OrderingModeDecl | EmptyOrderDecl | RevalidationDecl | CopyNamespacesDecl | DecimalFormatDecl
[198]    RevalidationDecl    ::=    "declare" "revalidation" ("strict" | "lax" | "skip")

The Prolog is extended by adding a new kind of Setter called a revalidation declaration. [Definition: A revalidation declaration sets the revalidation mode in the static context of the module, overriding any implementation-defined default.] If a Prolog contains more than one revalidation declaration, a static error is raised [err:XUST0003]. Revalidation mode controls the process by which type information is recovered for an updated document, as described in [8.2.4 upd:revalidate]

4.2 Function Declaration

[26]    AnnotatedDecl    ::=    "declare" (CompatibilityAnnotation | Annotation)* (VarDecl | FunctionDecl)
[33]    FunctionDecl    ::=    "function" EQName "(" ParamList? ")" ("as" SequenceType)? (FunctionBody | "external")
[36]    FunctionBody    ::=    EnclosedExpr

Functions can be declared as updating functions using the %updating annotation, or the equivalent backwards-compatible bare keyword updating. The built-in function fn:put is also specified as an updating function. If a function is not declared with the %updating annotation, or if it is declared with the %simple annotation it is a simple function.

Category Rules:
Additional Semantics:

XQuery Update Facility 3.0 allows an updating function to return both a non-empty pending update list and a non-empty XDM instance.

If the result of an updating function does not match its declared return type (after applying function conversion rules as specified in Section 3.1.5 Function CallsXQ), a type error is raised [err:XPTY0004]XQ30. The default return type of an updating function is item()*.

The means by which an external function returns an XDM instance or a pending update list is implementation-defined.

Example:
  • This function takes an element, a QName, and an atomic value. If the given element has an attribute with the given QName, the function updates the attribute with the given value; otherwise it inserts a new attribute with the given name and value.

    declare %updating function 
       upsert($e as element(), 
              $an as xs:QName, 
              $av as xs:anyAtomicType) 
       {
       let $ea := $e/attribute()[fn:node-name(.) = $an]
       return
          if (fn:empty($ea))
          then insert node attribute {$an} {$av} into $e
          else replace value of node $ea with $av
       }

4.3 Variable Declaration

[26]    AnnotatedDecl    ::=    "declare" (CompatibilityAnnotation | Annotation)* (VarDecl | FunctionDecl)
[29]    VarDecl    ::=    "variable" "$" VarName TypeDeclaration? ((":=" VarValue) | ("external" (":=" VarDefaultValue)?))
[30]    VarValue    ::=    ExprSingle
[31]    VarDefaultValue    ::=    ExprSingle
Category Rules:

4.4 Context Item Declaration

[32]    ContextItemDecl    ::=    "declare" "context" "item" ("as" ItemType)? ((":=" VarValue) | ("external" (":=" VarDefaultValue)?))
[30]    VarValue    ::=    ExprSingle
[31]    VarDefaultValue    ::=    ExprSingle
Category Rules: