View Old View New View Both View Only Previous Next

This draft contains only sections that have differences from the version that it modified.

W3C

XQuery 4.0: An XML Query Language

W3C Editor's Draft 23 February 2026

This version:
https://qt4cg.org/specifications/xquery-40/
Most recent version of XQuery:
https://qt4cg.org/specifications/xquery-40/
Most recent Recommendation of XQuery:
https://www.w3.org/TR/2017/REC-xquery-31-20170321/
Editor:
Michael Kay, Saxonica <mike@saxonica.com>

Please check the errata for any errors or issues reported since publication.

See also translations.

This document is also available in these non-normative formats: XML.


Abstract

XML is a versatile markup language, capable of labeling the information content of diverse data sources, including structured and semi-structured documents, relational databases, and object repositories. A query language that uses the structure of XML intelligently can express queries across all these kinds of data, whether physically stored in XML or viewed as XML via middleware. This specification describes a query language called XQuery, which is designed to be broadly applicable across many types of XML data sources.

A list of changes made since XQuery 3.1 can be found in J Change Log.

Status of this Document

This is a draft prepared by the QT4CG (officially registered in W3C as the XSLT Extensions Community Group). Comments are invited.

Dedication

The publications of this community group are dedicated to our co-chair, Michael Sperberg-McQueen (1954–2024).


2 Basics

2.2 Expression Context

[Definition: The expression context for a given expression consists of all the information that can affect the result of the expression.]

This information is organized into two categories called the static context and the dynamic context.

2.2.1 Static Context

Changes in 4.0  

  1. The default namespace for elements and types can be set to the value ##any, allowing unprefixed names in axis steps to match elements with a given local name in any namespace.   [Issue 296 PR 1181 30 April 2024]

  2. Parts of the static context that were there purely to assist in static typing, such as the statically known documents, were no longer referenced and have therefore been dropped.   [Issue 1343 PR 1344 23 September 2024]

  3. The context value static type, which was there purely to assist in static typing, has been dropped.   [Issue 1495 PR 1496 29 October 2024]

  4. Named record types used in the signatures of built-in functions are now available as standard in the static context.   [Issue 835 PR 1991 11 May 2025]

[Definition: The static context of an expression is the information that is available during static analysis of the expression, prior to its evaluation.] This information can be used to decide whether the expression contains a static error.

The individual components of the static context are described below.

In XQuery 4.0, the static context for an expression is largely defined in the query prolog of a module: see 5 Modules and Prologs. Declarations in the prolog, such as variable declarations, function declarations, and decimal format declarations populate the static context for expressions appearing within the module. In some cases (but not all) these declarations may affect the static context for expressions that precede the relevant declaration. The static context can also be affected by declarations in other modules that are referenced using an import module declaration: see 5.12 Module Import.

In addition, some expressions modify the static context for their subexpressions. The most obvious example is in-scope variables (a FLWORExpr declares bindings of local variables that are available for reference within subsequent clauses of the expression). A further example is the statically known namespaces: an element constructor may contain namespace declarations such as xmlns:p="some_uri" which cause additional namespace prefixes to be available within the content of the element constructor.

Appendix B.1 Static Context Components gives an overview of the components in the static context and the way they are initialized.

Some components of the static context, but not all, also affect the dynamic semantics of expressions. For example, casting of a string such as "xbrl:xbrl" to an xs:QName might expand the prefix xbrl to the namespace URI http://www.xbrl.org/2003/instance using the statically known namespaces from the static context; since the input string "xbrl:xbrl" is in general not known until execution time (it might be read from a source document), this means that the values of the statically known namespaces must be available at execution time.

  • [Definition: XPath 1.0 compatibility mode.This component must be set by all host languages that include XPath 3.1 as a subset, indicating whether rules for compatibility with XPath 1.0 are in effect. XQuery sets the value of this component to false. ]

  • [Definition: Statically known namespaces. This is a mapping from prefix to namespace URI that defines all the namespaces that are known during static processing of a given expression.]

    The URI value is whitespace normalized according to the rules for the xs:anyURI type in 3.2.17 anyURI XS1-2 or 3.3.17 anyURI XS11-2.

    The statically known namespaces may include a binding for the zero-length prefix: however, this is used only by the constructed element namespace rule.

    Note the difference between in-scope namespaces, which is a dynamic property of an element node, and statically known namespaces, which is a static property of an expression.

    Some namespaces are predeclared (see 2.1.4 Namespaces and QNames); additional namespaces can be added to the statically known namespaces by namespace declarations, schema imports, or module imports in a Prolog, by a module declaration, and by namespace declaration attributes in direct element constructors.

  • [Definition: Default namespace for elements and types. This is either a namespace URI, or the special value "##any", or absentDM. This indicates how unprefixed QNames are interpreted when they appear in a position where an element name or type name is expected.]

    • If the value is set to a namespace URI, this namespace is used for any such unprefixed QName. The URI value is whitespace-normalized according to the rules for the xs:anyURI type in 3.2.17 anyURI XS1-2 or 3.3.17 anyURI XS11-2.

    • The special value "##any" indicates that:

      • When an unprefixed QName is used as a name test for selecting named elements in an axis step, the name test will match an element having the specified local name, in any namespace or none.

      • When an unprefixed QName is used in a context where a type name is expected (but not as a function name), the default namespace is the xs namespace, http://www.w3.org/2001/XMLSchema.

      • In any other context, an unprefixed QName represents a name in no namespace.

    • If the value is absentDM, an unprefixed QName representing an element or type name is interpreted as being in no namespace.

  • [Definition: Default function namespace. This determines how unprefixed lexical QNames appearing in static functiona static function call calls or named functionor a named function reference references are interpreted.]

    There are three possible settings:

    1. The property may be absentDM. In this case an unprefixed lexicallexical QName QName appearing in a staticstatic function call function call or in a namednamed function reference function reference is resolved first by searching the static context for a functionfunction definition declaration in no namespace, having a matching local name and arity rangearity range; if that fails to find a matching function declarationdefinition, a second search is conducted looking for a functionfunction definition declaration in the namespace http://www.w3.org/2005/xpath-functions, again having a matching local name and arity rangearity range.

    2. The property may be set to the empty URI, "". In this case an unprefixed lexicallexical QName QName appearing in a staticstatic function call function call or a namednamed function reference function reference is resolved by searching the static context for a functionfunction definition declaration in no namespace, having a matching local name and arity rangearity range.

    3. The property may be set to an explicit URI, say NS. In this case an unprefixed lexicallexical QName QName appearing in a staticstatic function call function call or a namednamed function reference function reference is resolved by searching the static context for a functionfunction definition declaration in namespace NS, having a matching local name and arity rangearity range.

    The URI value is whitespace-normalized according to the rules for the xs:anyURI type in 3.2.17 anyURI XS1-2 or 3.3.17 anyURI XS11-2

    Host languages may use a more complex algorithm for resolving function names. For example XSLT resolves ambiguities using the concept of import precedence.

    In XQuery, a default function namespace can be declared in the prolog in a default function namespace declaration (see 5.14 Default Namespace Declaration); in the absence of such a declaration, the namespace http://www.w3.org/2005/xpath-functions is used.

  • [Definition: In-scope schema definitions is a generic term for all the element declarations, attribute declarations, and schema type definitions that are in scope during static analysis of an expression.] It includes the following three parts:

    • [Definition: In-scope schema types. Each schema type definition is identified either by an expanded QName (for a named type) or by an implementation-dependent type identifier (for an anonymous type). The in-scope schema types include the predefined schema types described in 3.5 Schema Types. If the Schema Aware Feature is supported, in-scope schema types also include all type definitions found in imported schemas. ]

    • [Definition: In-scope element declarations. Each element declaration is identified either by an expanded QName (for a top-level element declaration) or by an implementation-dependent element identifier (for a local element declaration). If the Schema Aware Feature is supported, in-scope element declarations include all element declarations found in imported schemas. ] An element declaration includes information about the element’s substitution group affiliation.

      [Definition: Substitution groups are defined in 2.2.2.2 Element Substitution Group XS1-1 and 2.2.2.2 Element Substitution Group XS11-1. Informally, the substitution group headed by a given element (called the head element) consists of the set of elements that can be substituted for the head element without affecting the outcome of schema validation.]

    • [Definition: In-scope attribute declarations. Each attribute declaration is identified either by an expanded QName (for a top-level attribute declaration) or by an implementation-dependent attribute identifier (for a local attribute declaration). If the Schema Aware Feature is supported, in-scope attribute declarations include all attribute declarations found in imported schemas. ]

  • [Definition: In-scope variables. This is a mapping from expanded QNames to sequence types. It defines the set of variables that are available for reference within an expression. The expanded QName is the name of the variable, and the type is the static type of the variable.]

    Variable declarations in a Prolog are added to in-scope variables. An expression that binds a variable extends the in-scope variables, within the scope of the variable, with the variable and its type. Within the body of an inline function expression or user-defined function, the in-scope variables are extended by the names and types of the function parameters.

    The static type of a variable may either be declared in a query or inferred by static type inference as discussed in 2.3.3.1 Static Analysis Phase.

  • [Definition: In-scope named item types. This is a mapping from expanded QNames to named item types.]

    [Definition: A named item type is an ItemType identified by an expanded QName.]

    Named item types serve two purposes:

    • They allow frequently used item types, especially complex item types such as record types, to be given simple names, to avoid repeating the definition every time it is used.

    • They allow the definition of recursive types, which are useful for describing recursive data structures such as lists and trees. For details see 3.2.8.3.1 Recursive Record Types.

    Certain named item types (typically item types used in the signatures of built-in functions) are always available in the static context. These are defined in [Functions and Operators 4.0] section C Built-in named record types.

    Note:

    In XQuery, named item types can be declared in the Query Prolog.

  • [Definition: Statically known function definitions. This is a set of function definitions.]

    Function definitions are described in 2.2.1.1 Function Definitions.

  • [Definition: Statically known collations. This is an implementation-defined mapping from URI to collation. It defines the names of the collations that are available for use in processing queries and expressions.] [Definition: A collation is a specification of the manner in which strings and URIs are compared and, by extension, ordered. For a more complete definition of collation, see [Functions and Operators 4.0] section 5.3 Comparison of strings.]

  • [Definition: Construction mode. The construction mode governs the behavior of element and document node constructors. If construction mode is preserve, the type of a constructed element node is xs:anyType, and all attribute and element nodes copied during node construction retain their original types. If construction mode is strip, the type of a constructed element node is xs:untyped; all element nodes copied during node construction receive the type xs:untyped, and all attribute nodes copied during node construction receive the type xs:untypedAtomic.]

  • [Definition: Default order for empty sequences. This component controls the processing of empty sequences and NaN values as ordering keys in an order by clause in a FLWOR expression, as described in 4.13.9 Order By Clause.] Its value may be greatest or least.

  • [Definition: Boundary-space policy. This component controls the processing of boundary whitespace by direct element constructors, as described in 4.12.1.4 Boundary Whitespace.] Its value may be preserve or strip.

  • [Definition: Copy-namespaces mode. This component controls the in-scope namespaces property that is assigned when an existing element node is copied by an element constructor, as described in 4.12.1 Direct Element Constructors. Its value consists of two parts: preserve or no-preserve, and inherit or no-inherit.]

  • [Definition: Static Base URI. This is an absolute URI, used to resolve relative URIs during static analysis. ] For example, it is used to resolve module location URIs in XQuery, and the URIs in xsl:import and xsl:include in XSLT. All expressions within a module have the same static base URI. The Static Base URI can be set using a base URI declaration.

    Relative URI references are resolved as described in 2.5.6 Resolving a Relative URI Reference.

    At execution time, relative URIs supplied to functions such as fn:doc are resolved against the Executable Base URI, which may or may not be the same as the Static Base URI.

  • [Definition: Statically known decimal formats. This is a mapping from QNames to decimal formats, with one default format that has no visible name, referred to as the unnamed decimal format. Each format is available for use when formatting numbers using the fn:format-number function.]

    Decimal formats are described in 2.2.1.2 Decimal Formats.

4 Expressions

This section discusses each of the basic kinds of expression. Each kind of expression has a name such as PathExpr, which is introduced on the left side of the grammar production that defines the expression. Since XQuery 4.0 is a composable language, each kind of expression is defined in terms of other expressions whose operators have a higher precedence. In this way, the precedence of operators is represented explicitly in the grammar.

The order in which expressions are discussed in this document does not reflect the order of operator precedence. In general, this document introduces the simplest kinds of expressions first, followed by more complex expressions. For the complete grammar, see Appendix [A XQuery 4.0 Grammar].

[Definition: A query consists of one or more modules.] If a query is executable, one of its modules has a Query Body containing an expression whose value is the result of the query. An expression is represented in the XQuery grammar by the symbol Expr.

Expr::=(ExprSingle ++ ",")
ExprSingle::=FLWORExpr
| QuantifiedExpr
| SwitchExpr
| TypeswitchExpr
| IfExpr
| TryCatchExpr
| OrExpr
ExprSingle::=FLWORExpr
| QuantifiedExpr
| SwitchExpr
| TypeswitchExpr
| IfExpr
| TryCatchExpr
| OrExpr
FLWORExpr::=InitialClauseIntermediateClause* ReturnClause
QuantifiedExpr::=("some" | "every") (QuantifierBinding ++ ",") "satisfies" ExprSingle
SwitchExpr::="switch" SwitchComparand (SwitchCases | BracedSwitchCases)
TypeswitchExpr::="typeswitch" "(" Expr ")" (TypeswitchCases | BracedTypeswitchCases)
IfExpr::="if" "(" Expr ")" (UnbracedActions | BracedAction)
TryCatchExpr::=TryClause ((CatchClause+ FinallyClause?) | FinallyClause)
OrExpr::=AndExpr ("or" AndExpr)*

The XQuery 4.0 operator that has lowest precedence is the comma operator, which is used to combine two operands to form a sequence. As shown in the grammar, a general expression (Expr) can consist of multiple ExprSingle operands, separated by commas.

The name ExprSingle denotes an expression that does not contain a top-level comma operator (despite its name, an ExprSingle may evaluate to a sequence containing more than one item.)

The symbol ExprSingle is used in various places in the grammar where an expression is not allowed to contain a top-level comma. For example, each of the arguments of a function call must be a ExprSingle, because commas are used to separate the arguments of a function call.

After the comma, the expressions that have next lowest precedence are FLWORExpr,QuantifiedExpr, SwitchExpr, TypeswitchExpr, IfExpr, TryCatchExpr, and OrExpr. Each of these expressions is described in a separate section of this document.

4.5 Functions

Functions in XQuery 4.0 arise in two ways:

The functions defined by a statically known function definition can be invoked using a static function call. Function items corresponding to these definitions can also be obtained, as dynamic values, by evaluating a named function reference. Function items can also be obtained using the fn:function-lookup function: in this case the function name and arity do not need to be known statically, and the function definition need not be present in the static context, so long as it is in the dynamic context.

Static and dynamic function calls are described in the following sections.

4.5.1 Static Function Calls

The static context for an expression includes a set of statically known function definitions. Every function definition in the static context has a name (which is an expanded QName) and an arity range, which is a range of permitted arities for calls on that function. Two function definitions having the same name must not have overlapping arity ranges. This means that for a given static function call, it is possible to identify the target function definition in the static context unambiguously from knowledge of the function name and the number of supplied arguments.

A static function call is bound to a function definition in the static context by matching the name and arity. If the function call has P positional arguments followed by K keyword arguments, then the required arity is P+K, and the static context must include a function definition whose name matches the expanded QName in the function call, and whose arity range includes this required arity. This is the function chosen to be called. The result of the function is obtained by evaluating the expression that forms its implementation, with a dynamic context that provides values for all the declared parameters, initialized as described in 4.5.1.2 Evaluating Static Function Calls below.

Similarly, a functionnamed function reference reference of the form f#N binds to a function definition in the static context whose name matches f where MinP ≤ N and MaxP ≥ N. The result of evaluating a function reference is a function item which can be called using a dynamic function call. Function items are never variadic and their arguments are always supplied positionally. For example, the function reference fn:concat#3 returns a function item with arity 3, which is always called by supplying three positional arguments, and whose effect is the same as a static call on fn:concat with three positional arguments.

The detailed rules for evaluating static function calls and function references are defined in subsequent sections.

5 Modules and Prologs

Module::=VersionDecl? (LibraryModule | MainModule)
VersionDecl::="xquery" (("encoding" StringLiteral) | ("version" StringLiteral ("encoding" StringLiteral)?)) Separator
LibraryModule::=ModuleDeclProlog
ModuleDecl::="module" "namespace" NCName "=" URILiteralSeparator
Prolog::=((DefaultNamespaceDecl | Setter | NamespaceDecl | Import) Separator)* ((ContextValueDecl | VarDecl | FunctionDecl | ItemTypeDecl | NamedRecordTypeDecl | OptionDecl) Separator)*
DefaultNamespaceDecl::="declare" "fixed"? "default" ("element" | "function") "namespace" URILiteral
Setter::=BoundarySpaceDecl | DefaultCollationDecl | BaseURIDecl | ConstructionDecl | OrderingModeDecl | EmptyOrderDecl | CopyNamespacesDecl | DecimalFormatDecl
BoundarySpaceDecl::="declare" "boundary-space" ("preserve" | "strip")
DefaultCollationDecl::="declare" "default" "collation" URILiteral
BaseURIDecl::="declare" "base-uri" URILiteral
ConstructionDecl::="declare" "construction" ("strip" | "preserve")
OrderingModeDecl::="declare" "ordering" ("ordered" | "unordered")
EmptyOrderDecl::="declare" "default" "order" "empty" ("greatest" | "least")
CopyNamespacesDecl::="declare" "copy-namespaces" PreserveMode "," InheritMode
DecimalFormatDecl::="declare" (("decimal-format" EQName) | ("default" "decimal-format")) (DFPropertyName "=" StringLiteral)*
NamespaceDecl::="declare" "namespace" NCName "=" URILiteral
Import::=SchemaImport | ModuleImport
SchemaImport::="import" "schema" SchemaPrefix? URILiteral ("at" (URILiteral ++ ","))?
ModuleImport::="import" "module" ("namespace" NCName "=")? URILiteral ("at" (URILiteral ++ ","))?
Separator::=";"
ContextValueDecl::="declare" "context" (("value" ("as" SequenceType)?) | ("item" ("as" ItemType)?)) ((":=" VarValue) | ("external" (":=" VarDefaultValue)?))
VarDecl::="declare" Annotation* "variable" VarNameAndType ((":=" VarValue) | ("external" (":=" VarDefaultValue)?))
FunctionDecl::="declare" Annotation* "function" EQName "(" ParamListWithDefaults? ")" TypeDeclaration? (FunctionBody | "external")
/* xgc: reserved-function-names */
ItemTypeDecl::="declare" Annotation* "type" EQName "as" ItemType
NamedRecordTypeDecl::="declare" Annotation* "record" EQName "(" (ExtendedFieldDeclaration ** ",") ExtensibleFlag? ")"
OptionDecl::="declare" "option" EQNameStringLiteral
MainModule::=PrologQueryBody
QueryBody::=Expr
Expr::=(ExprSingle ++ ",")

A query can be assembled from one or more fragments called modules. [Definition: A module is a fragment of XQuery code that conforms to the Module grammar and can independently undergo the static analysis phase described in 2.3.3 Expression Processing. Each module is either a main module or a library module.]

[Definition: A main module consists of a Prolog followed by a Query Body.] A query has exactly one main module. In a main module, the Query Body is evaluated with respect to the static and dynamic contexts of the main module in which it is found, and its value is the result of the query.

[Definition: A module that does not contain a Query Body is called a library module. A library module consists of a module declaration followed by a Prolog.] A library module cannot be evaluated directly; instead, it provides function and variable declarations that can be imported into other modules.

The XQuery syntax does not allow a module to contain both a module declaration and a Query Body.

[Definition: A Prolog is a series of declarations and imports that define the processing environment for the module that contains the Prolog.] Each declaration or import is followed by a semicolon. A Prolog is organized into two parts.

The first part of the Prolog consists of setters, imports, namespace declarations, and default namespace declarations. [Definition: Setters are declarations that set the value of some property that affects query processing, such as construction mode or default collation.] Namespace declarations and default namespace declarations affect the interpretation of lexical QNames within the query. Imports are used to import definitions from schemas and modules. [Definition: The target namespace of a module is the namespace of the objects (such as elements or functions) that it defines. ]

The second part of the Prolog consists of declarations of variables, functions, and options. These declarations appear at the end of the Prolog because they may be affected by declarations and imports in the first part of the Prolog.

[Definition: The Query Body, if present, consists of an expression that defines the result of the query.] Evaluation of expressions is described in 4 Expressions. A module can be evaluated only if it has a Query Body.

5.14 Default Namespace Declaration

Changes in 4.0  

  1. The default namespace for elements and types can now be declared to be fixed for a query module, meaning it is unaffected by a namespace declaration appearing on a direct element constructor.   [Issue 65 PR 753 31 October 2023]

  2. The default namespace for elements and types can be set to the value ##any, allowing unprefixed names in axis steps to match elements with a given local name in any namespace.   [Issue 296 PR 1181 30 April 2023]

  3. The effect of not declaring a default function namespace has changed: user-defined functions can now be in no namespace, and a search for an unprefixed function name will be resolved first against functions in no namespace, and only then against functions in the standard function namespace.   [ PRIssues 657  2235 PRs 2200 2236 7 October 2025]

DefaultNamespaceDecl::="declare" "fixed"? "default" ("element" | "function") "namespace" URILiteral
URILiteral::=StringLiteral
StringLiteral::=AposStringLiteral | QuotStringLiteral
/* ws: explicit */

Default namespace declarations can be used in a Prolog to facilitate the use of unprefixed QNames.

The namespace URI specified in a default namespace declaration must not be http://www.w3.org/XML/1998/namespace or http://www.w3.org/2000/xmlns/ [err:XQST0070].

The followingThere are two kinds of default namespace declarations are supported:, described in the following sections.

  • A default element namespace declaration declares how unprefixed element and type names are to be interpreted. The relevant value is recorded as the default namespace for elements and types in the static context for the query module. A Prolog may contain at most one default element namespace declaration and it must not contain both a default element namespace declaration and an import schema declaration that specifies a default element namespace [err:XQST0066].

    The URILiteral may take one of the following forms:

    • A namespace URI. This namespace will typically be used for unprefixed names appearing where an element or type name is expected.

    • The empty string "". In this case unprefixed names appearing where an element or type name is expected are treated as being in no namespace: the default namespace for elements and types is set to absentDM.

    • The string "##any". In this case an unprefixed name appearing as a NameTest in an axis step whose principal node kind is element is interpreted as a wildcard (the unprefixed name N is treated as equivalent to the wildcard *:N); an unprefixed name used appearing where an item type name is expected is interpreted as a local name in namespace http://www.w3.org/2001/XMLSchema, while an unprefixed name appearing in any other context where an element or type name is expected is treated as being in no namespace.

      Note:

      To take an example, older versions of the internet index of RFCs (requests for comments) use the namespace URI http://www.rfc-editor.org/rfc-index, while newer versions use https://www.rfc-editor.org/rfc-index (note the change of URI scheme). XPath code that needs to work with either version can be simplified by setting the default namespace to ##any: but be aware that this might lead to spurious matching of names in an unrelated namespace.

    The following example illustrates the declaration of a default namespace for elements and types:

    declare default element namespace "http://example.org/names";

    If no default element namespace declaration is present, unprefixed element and type names are in no namespace (however, an implementation may define a different default as specified in B.1 Static Context Components.)

    If the keyword "fixed", is present, the default namespace for elements and types is fixed throughout the module, and is not affected by default namespace declarations (xmlns="") appearing on direct element constructors.

  • A default function namespace declaration declares a namespace URI that is associated with unprefixed function names in static function calls and function declarations.

    The following example illustrates the declaration of a default function namespace:

    declare default function namespace "http://www.w3.org/2005/xpath-functions/math";

    A Prolog may contain at most one default function namespace declaration [err:XQST0066].

    There are three cases to consider.

    1. If there is an explicit default function namespace declaration and the StringLiteral is a zero-length string, the default function namespace is absentDM.

      In this case:

      1. Any function declaration using an unprefixed lexical QName declares a function in no namespace.

      2. Any static function call or named function reference using an unprefixed lexical QName refers to a function in no namespace.

      3. Any function whose name is in a namespace (including the standard function namespace http://www.w3.org/2005/xpath-functions) can be referenced only by using an explicit namespace prefix (for example, fn:abs(3)) or an EQName that identifies the namespace explicitly (for example, Q{http://www.w3.org/2005/xpath-functions}abs(3)).

    2. If there is an explicit default function namespace declaration and the StringLiteral is a non-zero-length string (call it NS), the default function namespace is set to NS.

      In this case:

      1. Any function declaration using an unprefixed lexical QName declares a function in namespace NS.

      2. Any static function call or named function reference using an unprefixed lexical QName refers to a function in namespace NS.

      3. Any function whose name is in a different namespace (including the standard function namespace http://www.w3.org/2005/xpath-functions) can be referenced only by using an explicit namespace prefix (for example fn:abs($x)), or using an EQName that explicitly identifies the namespace (for example Q{http://www.w3.org/2005/xpath-functions}abs($x)).

      4. Any function whose name is in no namespace (for example, a constructor function for an atomic type declared in a no-namespace schema) can be called only by using a no-namespace EQName, for example Q{}local-name($x).

    3. If there is no explicit default function namespace declaration, then:

      1. Any function declaration using an unprefixed lexical QName declares a function in no namespace.

        Note:

        This is allowed only for functions in the main module, and for private functions in a library module.

        In previous XQuery versions this would have been an error, as the default namespace http://www.w3.org/2005/xpath-functions was (and remains) a reserved namespace.

      2. Any static function call or named function reference using an unprefixed lexical QName is resolved by first searching the static context for a declaration of a no-namespace function having the right local name and arity range, and if that is unsuccessful, by searching for a function in the standard function namespace http://www.w3.org/2005/xpath-functions having the right local name and arity range.

        A no-namespace function can be referenced without risk of ambiguity by using a no-namespace EQName, for example Q{}local-name($x).

        A function in the standard function namespace http://www.w3.org/2005/xpath-functions can be referenced without risk of ambiguity by using the pre-declared namespace prefix fn (for example fn:abs($x)), or by using an EQName that explicitly identifies the namespace (for example Q{http://www.w3.org/2005/xpath-functions}abs($x)).

    The keyword "fixed" has no effect when declaring a default function namespace, since there is no mechanism to change the default function namespace within a query module.

Unprefixed attribute names and variable names are in no namespace.

5.14.1 Default Element Namespace Declaration

A default element namespace declaration declares how unprefixed element and type names are to be interpreted. The relevant value is recorded as the default namespace for elements and types in the static context for the query module. A Prolog may contain at most one default element namespace declaration and it must not contain both a default element namespace declaration and an import schema declaration that specifies a default element namespace [err:XQST0066].

The URILiteral may take one of the following forms:

  • A namespace URI. This namespace will typically be used for unprefixed names appearing where an element or type name is expected.

  • The empty string "". In this case unprefixed names appearing where an element or type name is expected are treated as being in no namespace: the default namespace for elements and types is set to absentDM.

  • The string "##any". In this case an unprefixed name appearing as a NameTest in an axis step whose principal node kind is element is interpreted as a wildcard (the unprefixed name N is treated as equivalent to the wildcard *:N); an unprefixed name used appearing where an item type name is expected is interpreted as a local name in namespace http://www.w3.org/2001/XMLSchema, while an unprefixed name appearing in any other context where an element or type name is expected is treated as being in no namespace.

    Note:

    To take an example, older versions of the internet index of RFCs (requests for comments) use the namespace URI http://www.rfc-editor.org/rfc-index, while newer versions use https://www.rfc-editor.org/rfc-index (note the change of URI scheme). XPath code that needs to work with either version can be simplified by setting the default namespace to ##any: but be aware that this might lead to spurious matching of names in an unrelated namespace.

The following example illustrates the declaration of a default namespace for elements and types:

declare default element namespace "http://example.org/names";

If no default element namespace declaration is present, unprefixed element and type names are in no namespace (however, an implementation may define a different default as specified in B.1 Static Context Components.)

If the keyword "fixed", is present, the default namespace for elements and types is fixed throughout the module, and is not affected by default namespace declarations (xmlns="") appearing on direct element constructors.

5.14.2 Default Function Namespace Declaration

A default function namespace declaration declares a namespace URI that is associated with unprefixed function names in static function calls and named function references. It also affects the interpretation of unprefixed lexical QNames used in function declarations.

The following example illustrates the declaration of a default function namespace:

declare default function namespace "http://www.w3.org/2005/xpath-functions/math";

A Prolog may contain at most one default function namespace declaration [err:XQST0066].

There are three cases to consider.

  1. If there is an explicit default function namespace declaration and the StringLiteral is a zero-length string, the default function namespace is absentDM.

    In this case:

    1. Any function declaration using an unprefixed lexical QName declares a function in no namespace.

    2. Any static function call or named function reference using an unprefixed lexical QName refers to a function in no namespace.

    3. Any function whose name is in a namespace (including the standard function namespace http://www.w3.org/2005/xpath-functions) can be referenced only by using an explicit namespace prefix (for example, fn:abs(3)) or an EQName that identifies the namespace explicitly (for example, Q{http://www.w3.org/2005/xpath-functions}abs(3)).

  2. If there is an explicit default function namespace declaration and the StringLiteral is a non-zero-length string (call it NS), the default function namespace is set to NS.

    In this case:

    1. Any function declaration using an unprefixed lexical QName declares a function in namespace NS.

    2. Any static function call or named function reference using an unprefixed lexical QName refers to a function in namespace NS.

    3. Any function whose name is in a different namespace (including the standard function namespace http://www.w3.org/2005/xpath-functions) can be referenced only by using an explicit namespace prefix (for example fn:abs($x)), or using an EQName that explicitly identifies the namespace (for example Q{http://www.w3.org/2005/xpath-functions}abs($x)).

    4. Any function whose name is in no namespace (for example, a constructor function for an atomic type declared in a no-namespace schema) can be called only by using a no-namespace EQName, for example Q{}local-name($x).

  3. If there is no explicit default function namespace declaration, then:

    1. Any function declaration using an unprefixed lexical QName declares a function in no namespace.

      Note:

      This is allowed only for functions in the main module, and for private functions in a library module.

      In previous XQuery versions this would have been an error, as the default namespace http://www.w3.org/2005/xpath-functions was (and remains) a reserved namespace.

    2. Any static function call or named function reference using an unprefixed lexical QName is resolved by first searching the static context for a declaration of a no-namespace function having the right local name and arity range, and if that is unsuccessful, by searching for a function in the standard function namespace http://www.w3.org/2005/xpath-functions having the right local name and arity range.

      A no-namespace function can be referenced without risk of ambiguity by using a no-namespace EQName, for example Q{}local-name($x).

      A function in the standard function namespace http://www.w3.org/2005/xpath-functions can be referenced without risk of ambiguity by using the pre-declared namespace prefix fn (for example fn:abs($x)), or by using an EQName that explicitly identifies the namespace (for example Q{http://www.w3.org/2005/xpath-functions}abs($x)).

The keyword "fixed" has no effect when declaring a default function namespace, since there is no mechanism to change the default function namespace within a query module.

G Glossary (Non-Normative)

absolute path expression

An absolute path expression is an instance of the production AbsolutePathExpr: it consists of either (a) the operator / followed by zero or more operands separated by / or // operators, or (b) the operator // followed by one or more operands separated by / or // operators.

and expression

An and expression is a non-trivial instance of the production AndExpr.

anonymous function

An anonymous function is a function item with no name. Anonymous functions may be created, for example, by evaluating an inline function expression or by partial function application.

application function

Application functions are function definitions written in a host language such as XQuery or XSLT whose syntax and semantics are defined in this family of specifications. Their behavior (including the rules determining the static and dynamic context) follows the rules for such functions in the relevant host language specification.

argument expression

An argument to a function call is either an argument expression or an ArgumentPlaceholder (?); in both cases it may either be supplied positionally, or identified by a name (called a keyword).

arity range

A function definition has an arity range, which is a range of consecutive non-negative integers. If the function definition has M required parameters and N optional parameters, then its arity range is from M to M+N inclusive.

array

An array is a function item that associates a set of positions, represented as positive integer keys, with values.

associated value

The value associated with a given key is called the associated value of the key.

atomic item

An atomic item is a value in the value space of an atomic type, as defined in [XML Schema 1.0] or [XML Schema 1.1].

atomic type

An atomic type is a simple schema type whose {variety}XS11-1 is atomic.

atomization

Atomization of a sequence is defined as the result of invoking the fn:data function, as defined in [Functions and Operators 4.0] section 12.1.6 fn:data.

available binary resources

Available binary resources. This is a mapping of strings to binary resources. Each string represents the absolute URI of a resource. The resource is returned by the fn:unparsed-binary function when applied to that URI.

available documents

Available documents. This is a mapping of strings to document nodes. Each string represents the absolute URI of a resource. The document node is the root of a tree that represents that resource using the data model. The document node is returned by the fn:doc function when applied to that URI.

available item collections

Available collections. This is a mapping of strings to sequences of items. Each string represents the absolute URI of a resource. The sequence of items represents the result of the fn:collection function when that URI is supplied as the argument.

available text resources

Available text resources. This is a mapping of strings to text resources. Each string represents the absolute URI of a resource. The resource is returned by the fn:unparsed-text function when applied to that URI.

available uri collections

Available URI collections. This is a mapping of strings to sequences of URIs. The string represents the absolute URI of a resource which can be interpreted as an aggregation of a number of individual resources each of which has its own URI. The sequence of URIs represents the result of the fn:uri-collection function when that URI is supplied as the argument.

axis step

An axis step is an instance of the production AxisStep: it is an expression that returns a sequence of GNodes that are reachable from a starting GNode via a specified axis. An axis step has three parts: an axis, which defines the direction of movement for the step, a node test, which selects GNodes based on their properties, and zero or more predicates which are used to filter the results.

base URI declaration

A base URI declaration specifies the Static Base URI property. The Static Base URI property is used when resolving relative URI references.

binding collection

In a for clause, when an expression is preceded by the keyword in, the value of that expression is called a binding collection.

binding sequence

In a window clause, when an expression is preceded by the keyword in, the value of that expression is called a binding sequence.

boundary-space declaration

A boundary-space declaration sets the boundary-space policy in the static context, overriding any implementation-defined default. Boundary-space policy controls whether boundary whitespace is preserved by element constructors during processing of the query.

boundary-space policy

Boundary-space policy. This component controls the processing of boundary whitespace by direct element constructors, as described in 4.12.1.4 Boundary Whitespace.

boundary whitespace

Boundary whitespace is a sequence of consecutive whitespace characters within the content of a direct element constructor, that is delimited at each end either by the start or end of the content, or by a DirectConstructor, or by an EnclosedExpr. For this purpose, characters generated by character references such as &#x20; or by CDataSections are not considered to be whitespace characters.

character reference

A character reference is an XML-style reference to a [Unicode] character, identified by its decimal or hexadecimal codepoint.

choice item type

A choice item type defines an item type that is the union of a number of alternatives. For example the type (xs:hexBinary | xs:base64Binary) defines the union of these two primitive atomic types, while the type (map(*) | array(*)) matches any item that is either a map or an array.

coercion rules

The coercion rules are rules used to convert a supplied value to a required type, for example when converting an argument of a function call to the declared type of the function parameter.

collation

A collation is a specification of the manner in which strings and URIs are compared and, by extension, ordered. For a more complete definition of collation, see [Functions and Operators 4.0] section 5.3 Comparison of strings.

comma operator

A comma operator is a comma used specifically as the operator in a sequence expression.

complex terminal

A complex terminal is a variable terminal whose production rule references, directly or indirectly, an ordinary production rule.

computed element constructor

A computed element constructor creates an element node, allowing both the name and the content of the node to be computed.

constructed element namespace rule

When an unprefixed lexical QName is expanded using the constructed element namespace rule, then it uses the namespace URI that is bound to the empty (zero-length) prefix in the statically known namespaces of the static context. If there is no such namespace binding then it uses the no-namespace rule.

construction declaration

A construction declaration sets the construction mode in the static context, overriding any implementation-defined default.

construction mode

Construction mode. The construction mode governs the behavior of element and document node constructors. If construction mode is preserve, the type of a constructed element node is xs:anyType, and all attribute and element nodes copied during node construction retain their original types. If construction mode is strip, the type of a constructed element node is xs:untyped; all element nodes copied during node construction receive the type xs:untyped, and all attribute nodes copied during node construction receive the type xs:untypedAtomic.

constructor function

The constructor function for a given simple type is used to convert instances of other simple types into the given type. The semantics of the constructor function call T($arg) are defined to be equivalent to the expression $arg cast as T?.

content expression

In an enclosed expression, the optional expression enclosed in curly brackets is called the content expression.

context dependent

A function definition is said to be context dependent if its result depends on the static or dynamic context of its caller. A function definition may be context-dependent for some arities in its arity range, and context-independent for others: for example fn:name#0 is context-dependent while fn:name#1 is context-independent.

context node

When the context value is a single item, it can also be referred to as the context item; when it is a single node, it can also be referred to as the context node.

context position

The context position is the position of the context value within the series of values currently being processed.

context size

The context size is the number of values in the series of values currently being processed.

context value

The context value is the value currently being processed.

copy-namespaces declaration

A copy-namespaces declaration sets the value of copy-namespaces mode in the static context, overriding any implementation-defined default. Copy-namespaces mode controls the namespace bindings that are assigned when an existing element node is copied by an element constructor or document constructor.

copy-namespaces mode

Copy-namespaces mode. This component controls the in-scope namespaces property that is assigned when an existing element node is copied by an element constructor, as described in 4.12.1 Direct Element Constructors. Its value consists of two parts: preserve or no-preserve, and inherit or no-inherit.

current dateTime

Current dateTime. This information represents an implementation-dependent point in time during the processing of a query , and includes an explicit timezone. It can be retrieved by the fn:current-dateTime function. If called multiple times during the execution of a query , this function always returns the same result.

data model

XQuery 4.0 operates on the abstract, logical structure of an XML document or JSON object rather than its surface syntax. This logical structure, known as the data model, is defined in [XDM 4.0].

decimal-format declaration

A decimal format declaration adds a decimal format to the statically known decimal formats, which define the properties used to format numbers using the fn:format-number() function

decimal-separator

decimal-separator(M, R) is used to separate the integer part of the number from the fractional part. The default value for both the marker and the rendition is U+002E (FULL STOP, PERIOD, .) .

default annotation namespace rule

When an unprefixed lexical QName is expanded using the annotation namespace rule, then it uses the namespace URI http://www.w3.org/2012/xquery.

default calendar

Default calendar. This is the calendar used when formatting dates in human-readable output (for example, by the functions fn:format-date and fn:format-dateTime) if no other calendar is requested. The value is a string.

default collation

Default collation. This identifies one of the collations in statically known collations as the collation to be used by functions and operators for comparing and ordering values of type xs:string and xs:anyURI (and types derived from them) when no explicit collation is specified.

default collation declaration

A default collation declaration sets the value of the default collation in the static context, overriding any implementation-defined default.

default collection

Default collection. This is the sequence of items that would result from calling the fn:collection function with no arguments.

default element namespace rule

When an unprefixed lexical QName is expanded using the default element namespace rule, then it uses the default namespace for elements and types. If this is absent, or if it takes the special value ##any, then the no-namespace rule is used.

default function namespace

Default function namespace. This determines how unprefixed lexical QNames appearing in static functiona static function call calls or named functionor a named function reference references are interpreted.

default function namespace rule

When an unprefixed lexical QName is expanded using the default function namespace rule, the processor searches for a matching function definition as follows: first, if the static context includes a no-namespace function definition with the required local name and arity, then that function definition is used; otherwise, the name is expanded using the default function namespace from the static context.

default in-scope namespace

The default in-scope namespace of an element node

default language

Default language. This is the natural language used when creating human-readable output (for example, by the functions fn:format-date and fn:format-integer) if no other language is requested. The value is a language code as defined by the type xs:language.

default namespace for elements and types

Default namespace for elements and types. This is either a namespace URI, or the special value "##any", or absentDM. This indicates how unprefixed QNames are interpreted when they appear in a position where an element name or type name is expected.

default order for empty sequences

Default order for empty sequences. This component controls the processing of empty sequences and NaN values as ordering keys in an order by clause in a FLWOR expression, as described in 4.13.9 Order By Clause.

default place

Default place. This is a geographical location used to identify the place where events happened (or will happen) when processing dates and times using functions such as fn:format-date, fn:format-dateTime, and fn:civil-timezone, if no other place is specified. It is used when translating timezone offsets to civil timezone names, and when using calendars where the translation from ISO dates/times to a local representation is dependent on geographical location. Possible representations of this information are an ISO country code or an Olson timezone name, but implementations are free to use other representations from which the above information can be derived. The only requirement is that it should uniquely identify a civil timezone, which means that country codes for countries with multiple timezones, such as the United States, are inadequate.

default type namespace rule

When an unprefixed lexical QName is expanded using the default type namespace rule, it uses the default namespace for elements and types. If this is absent, the no-namespace rule is used. If the default namespace for elements and types has the special value ##any, then the lexical QName refers to a name in the namespace http://www.w3.org/2001/XMLSchema.

default URI collection

Default URI collection. This is the sequence of URIs that would result from calling the fn:uri-collection function with no arguments.

delimiting terminal symbol

The delimiting terminal symbols are: !!=##)$%((#)**:+,--->->...////>::*:::=;<<!--<![CDATA[</<<<=<?==!>=>=?>>>=>>??>?[@[]]]>]```````[`{{{{|||}}`}}×÷AposStringLiteralBracedURILiteralQuotStringLiteralSStringLiteral

depends on

A variable value (or the context value) depends on another variable value (or the context value) if, during the evaluation of the initializing expression of the former, the latter is accessed through the module context.

derives from

A schema typeS1 is said to derive fromschema typeS2 if any of the following conditions is true:

digit

digit(M) is a character used in the picture string to represent an optional digit; the default value is U+0023 (NUMBER SIGN, #) .

direct element constructor

A direct element constructor is a form of element constructor in which the name of the constructed element is a constant.

document order

Informally, document order is the order in which nodes appear in the XML serialization of a document.

dynamically known function definitions

Dynamically known function definitions. This is a set of function definitions. It includes the statically known function definitions as a subset, but may include other function definitions that are not known statically.

dynamic context

The dynamic context of an expression is defined as information that is needed for the dynamic evaluation of an expression, beyond any information that is needed from the static context.

dynamic error

A dynamic error is an error that must be detected during the dynamic evaluation phase and may be detected during the static analysis phase.

dynamic evaluation phase

The dynamic evaluation phase is the phase during which the value of an expression is computed.

dynamic function call

is

dynamic type

Every value matches one or more sequence types. A value is said to have a dynamic typeT if it matches (or is an instance of) the sequence type T.

effective boolean value

The effective boolean value of a value is defined as the result of applying the fn:boolean function to the value.

effective case

The effective case of a switch expression is the first case clause that matches, using the rules given above, or the default clause if no such case clause exists.

effective case

The effective case in a typeswitch expression is the first case clause in which the value of the operand expression matches a SequenceType in the SequenceTypeUnion of the case clause, using the rules of SequenceType matching.

element name matching rule

When an unprefixed lexical QName is expanded using the element name matching rule rule, then it uses the default namespace for elements and types. If this is absent, then it uses the no-namespace rule. But if it takes the special value ##any, then the name is taken as matching any expanded QName with the corresponding local part, regardless of namespace: that is, the unprefixed name local is interpreted as *:local.

empty order declaration

An empty order declaration sets the default order for empty sequences in the static context, overriding any implementation-defined default. This declaration controls the processing of empty sequences and NaN values as ordering keys in an order by clause in a FLWOR expression.

empty sequence

A sequence containing zero items is called an empty sequence.

enclosed expression

An enclosed expression is an instance of the EnclosedExpr production, which allows an optional expression within curly brackets.

encoding declaration

If present, a version declaration may optionally include an encoding declaration. The value of the string literal following the keyword encoding is an encoding name, and must conform to the definition of EncName specified in [XML 1.0] [err:XQST0087]. The purpose of an encoding declaration is to allow the writer of a query to provide a string that indicates how the query is encoded, such as "UTF-8", "UTF-16", or "US-ASCII".

entry

Each key / value pair in a map is called an entry.

enumeration type

An EnumerationType accepts a fixed set of string values.

environment variables

Environment variables. This is a mapping from names to values. Both the names and the values are strings. The names are compared using an implementation-defined collation, and are unique under this collation. The set of environment variables is implementation-defined and may be empty.

equivalent grouping keys

Two tuples T1 and T2 have equivalent grouping keys if and only if, for each grouping variable GV, the atomized value of GV in T1 is deep-equal to the atomized value of GV in T2, as defined by applying the function fn:deep-equal using the appropriate collation.

error value

In addition to its identifying QName, a dynamic error may also carry a descriptive string and one or more additional values called error values.

Executable Base URI

Executable Base URI. This is an absolute URI used to resolve relative URIs during the evaluation of expressions; it is used, for example, to resolve a relative URI supplied to the fn:doc or fn:unparsed-text functions.

expanded QName

An expanded QName is a triple: its components are a prefix, a local name, and a namespace URI. In the case of a name in no namespace, the namespace URI and prefix are both absent. In the case of a name in the default namespace, the prefix is absent.

exponent-separator

exponent-separator(M, R) is used to separate the mantissa from the exponent in scientific notation. The default value for both the marker and the rendition is U+0065 (LATIN SMALL LETTER E, e) .

expression context

The expression context for a given expression consists of all the information that can affect the result of the expression.

extension expression

An extension expression is an expression whose semantics are implementation-defined.

external function

External functions can be characterized as functions that are neither part of the processor implementation, nor written in a language whose semantics are under the control of this family of specifications. The semantics of external functions, including any context dependencies, are entirely implementation-defined. In XSLT, external functions are called 24.1 Extension Functions XT30.

filter expression

A filter expression is an instance of the construct FilterExpr: that is, it is an expression in the form E1[E2]. Its effect is to return those items from the value of E1 that satisfy the predicate in E2.

filter expression for maps and arrays

A filter expression for maps and arrays is an instance of the construct FilterExprAM: that is, it is an expression in the form E1?[E2]. Its effect is to evaluate E1 to return an array or map, and to select members of the array, or entries from the map, that satisfy the predicate in E2.

fixed focus

A fixed focus is a focus for an expression that is evaluated once, rather than being applied to a series of values; in a fixed focus, the context value is set to one specific value, the context position is 1, and the context size is 1.

focus

The first three components of the dynamic context (context value, context position, and context size) are called the focus of the expression.

focus function

A focus function is an inline function expression in which the function signature is implicit: the function takes a single argument of type item()* (that is, any value), and binds this to the context value when evaluating the function body, which returns a result of type item()*.

function assertion

A function assertion is a predicate that restricts the set of functions matched by a FunctionType. It uses the same syntax as 5.15 Annotations.

function coercion

Function coercion wraps a function item in a new function whose signature is the same as the expected type. This effectively delays the checking of the argument and return types until the function is called.

function definition

A function definition contains information used to evaluate a static function call, including the name, parameters, and return type of the function.

function item

A function item is an item that can be called using a dynamic function call.

generalized atomic type

A generalized atomic type is an item type whose instances are all atomic items. Generalized atomic types include (a) atomic types, either built-in (for example xs:integer) or imported from a schema, (b) pure union types, either built-in (xs:numeric and xs:error) or imported from a schema, (c) choice item types if their alternatives are all generalized atomic types, and (d) enumeration types.

GNode

The term generic node or GNode is a collective term for XNodes (more commonly called simply nodes) representing the parts of an XML document, and JNodes, often used to represent the parts of a JSON document.

grouping key

The atomized value of a grouping variable is called a grouping key.

grouping-separator

grouping-separator(M, R) is used to separate groups of digits (for example as a thousands separator). The default value for both the marker and the rendition is U+002C (COMMA, ,) .

grouping variable

Each grouping specification specifies one grouping variable, which refers to variable bindings in the pre-grouping tuples. The values of the grouping variables are used to assign pre-grouping tuples to groups.

GTree

The term GTree means JTree or XTree.

guarded

An expression E is said to be guarded by some governing condition C if evaluation of E is not allowed to fail with a dynamic error except when C applies.

ignorable whitespace

Ignorable whitespace consists of any whitespace characters that may occur between terminals, unless these characters occur in the context of a production marked with a ws:explicit annotation, in which case they can occur only where explicitly specified (see A.3.4.2 Explicit Whitespace Handling).

implausible

Certain expressions, while not erroneous, are classified as being implausible, because they achieve no useful effect.

implementation defined

Implementation-defined indicates an aspect that may differ between implementations, but must be specified by the implementer for each particular implementation.

implementation dependent

Implementation-dependent indicates an aspect that may differ between implementations, is not specified by this or any W3C specification, and is not required to be specified by the implementer for any particular implementation.

implicit timezone

Implicit timezone. This is the timezone to be used when a date, time, or dateTime value that does not have a timezone is used in a comparison or arithmetic operation. The implicit timezone is an implementation-defined value of type xs:dayTimeDuration. See 3.2.7.3 Timezones XS1-2 or 3.3.7 dateTime XS11-2 for the range of valid values of a timezone.

infinity

infinity(R) is the string used to represent the double value infinity (INF); the default value is the string "Infinity"

initial context value

In the dynamic context of every module in a query, the context value component must have the same setting. If this shared setting is not absentDM, it is referred to as the initial context value.

initializing expression

If a variable declaration includes an expression (VarValue or VarDefaultValue), the expression is called an initializing expression. The static context for an initializing expression includes all functions, variables, and namespaces that are declared or imported anywhere in the Prolog.

inline function expression

An inline function expression is an instance of the construct InlineFunctionExpr. When evaluated, an inline function expression creates an anonymous function whose properties are defined directly in the inline function expression.

in-scope attribute declarations

In-scope attribute declarations. Each attribute declaration is identified either by an expanded QName (for a top-level attribute declaration) or by an implementation-dependent attribute identifier (for a local attribute declaration). If the Schema Aware Feature is supported, in-scope attribute declarations include all attribute declarations found in imported schemas.

in-scope element declarations

In-scope element declarations. Each element declaration is identified either by an expanded QName (for a top-level element declaration) or by an implementation-dependent element identifier (for a local element declaration). If the Schema Aware Feature is supported, in-scope element declarations include all element declarations found in imported schemas.

in-scope named item types

In-scope named item types. This is a mapping from expanded QNames to named item types.

in-scope namespaces

The in-scope namespaces property of an element node is a set of namespace bindings, each of which associates a namespace prefix with a URI.

in-scope schema definitions

In-scope schema definitions is a generic term for all the element declarations, attribute declarations, and schema type definitions that are in scope during static analysis of an expression.

in-scope schema type

In-scope schema types. Each schema type definition is identified either by an expanded QName (for a named type) or by an implementation-dependent type identifier (for an anonymous type). The in-scope schema types include the predefined schema types described in 3.5 Schema Types. If the Schema Aware Feature is supported, in-scope schema types also include all type definitions found in imported schemas.

in-scope variables

In-scope variables. This is a mapping from expanded QNames to sequence types. It defines the set of variables that are available for reference within an expression. The expanded QName is the name of the variable, and the type is the static type of the variable.

item

An item is either an atomic item, a node, or a function item.

item type

An item type is a type that can be expressed using the ItemType syntax, which forms part of the SequenceType syntax. Item types match individual items.

item type designator

An item type designator is a syntactic construct conforming to the grammar rule ItemType. An item type designator is said to designate an item type.

JNode

A JNode is a kind of item used to represent a value within the context of a tree of maps and arrays. A root JNode represents a map or array; a non-root JNode represents a member of an array or an entry in a map.

JTree

A tree that is rooted at a parentless JNode is referred to as a JTree.

kind test

An alternative form of a node test called a type test can select XNodes based on their type, or in the case of JNodes, the type of their contained ·content·

lexical QName

A lexical QName is a name that conforms to the syntax of the QName production

library module

A module that does not contain a Query Body is called a library module. A library module consists of a module declaration followed by a Prolog.

literal

A literal is a direct syntactic representation of an atomic item.

literal terminal

A literal terminal is a token appearing as a string in quotation marks on the right-hand side of an ordinary production rule.

logical expression

A logical expression is either an and expression or an or expression. If a logical expression does not raise an error, its value is always one of the boolean values true or false.

lookup expression

A lookup expression is an instance of the production LookupExpr: that is, an expression in the form E1?KS, where E1 is an expression returning a sequence of maps or arrays, and KS is a key specifier, which indicates which entries in a map, or members in an array, should be selected.

main module

A main module consists of a Prolog followed by a Query Body.

map

A map is a function that associates a set of keys with values, resulting in a collection of key / value pairs.

mapping arrow operator

The mapping arrow operator=!> applies a function to each item in a sequence.

may

MAY means that an item is truly optional.

member

The values of an array are called its members.

minus-sign

minus-sign(R) is the string used to mark negative numbers; the default value is U+002D (HYPHEN-MINUS, -) .

module

A module is a fragment of XQuery code that conforms to the Module grammar and can independently undergo the static analysis phase described in 2.3.3 Expression Processing. Each module is either a main module or a library module.

module declaration

A module declaration serves to identify a module as a library module. A module declaration begins with the keyword module and contains a namespace prefix and a URILiteral.

module import

A module import imports the public variable declarations, public function declarations, and public item type declarations from one or more library modules into the statically known function definitions, in-scope variables, or in-scope named item types of the importing module.

must

MUST means that the item is an absolute requirement of the specification.

must not

MUST NOT means that the item is an absolute prohibition of the specification.

named function reference

A named function reference is an instance of the production NamedFunctionRef: it is an expression (written name#arity) which evaluates to a function item, the details of the function item being based on the properties of a function definition in the static context.

named item type

A named item type is an ItemType identified by an expanded QName.

name expression

When an expression is used to specify the name of a constructed node, that expression is called the name expression of the constructor.

namespace binding

A namespace binding is a pair comprising a namespace prefix (which is either an xs:NCName or empty), and a namespace URI.

namespace declaration

A namespace declaration declares a namespace prefix and associates it with a namespace URI, adding the (prefix, URI) pair to the set of statically known namespaces.

namespace declaration attribute

A namespace declaration attribute is used inside a direct element constructor. Its purpose is to bind a namespace prefix (including the zero-length prefix) for the constructed element node, including its attributes.

namespace-sensitive

The namespace-sensitive types are xs:QName, xs:NOTATION, types derived by restriction from xs:QName or xs:NOTATION, list types that have a namespace-sensitive item type, and union types with a namespace-sensitive type in their transitive membership.

name test

A node test that consists only of an EQName or a Wildcard is called a name test.

NaN

NaN(R) is the string used to represent the double value NaN (not a number); the default value is the string "NaN"

node

Except where the context indicates otherwise, the term node is used as a synonym for XNode.

node test

A node test is a condition on the properties of a GNode. A node test determines which GNodes returned by an axis are selected by a step.

no-namespace rule

When an unprefixed lexical QName is expanded using the no-namespace rule, it is interpreted as having an absent namespace URI.

non-delimiting terminal symbol

The non-delimiting terminal symbols are: allowingancestorancestor-or-selfandarrayasascendingatattributebase-uriboundary-spacebycasecastcastablecatchchildcollationcommentconstructioncontextcopy-namespacescountdecimal-formatdecimal-separatordeclaredefaultdescendantdescendant-or-selfdescendingdigitdivdocumentdocument-nodeelementelseemptyempty-sequenceencodingendenumeqeveryexceptexponent-separatorexternalfalsefinallyfixedfnfollowingfollowing-or-selffollowing-siblingfollowing-sibling-or-selffollowsfollows-or-isforfunctiongegetgnodegreatestgroupgrouping-separatorgtidivifimportininfinityinheritinstanceintersectisis-notitemjnodekeylaxleleastletltmapmemberminus-signmodmodulenamespacenamespace-nodeNaNnenextno-inheritno-preservenodeofonlyoptionororderorderedorderingotherwiseparentpattern-separatorper-millepercentprecedesprecedes-or-isprecedingpreceding-or-selfpreceding-siblingpreceding-sibling-or-selfpreservepreviousprocessing-instructionrecordreturnsatisfiesschemaschema-attributeschema-elementselfslidingsomestablestartstrictstripswitchtextthentotreattruetrytumblingtypetypeswitchunionunorderedvalidatevaluevariableversionwhenwherewhilewindowxqueryzero-digitBinaryIntegerLiteralDecimalLiteralDoubleLiteralHexIntegerLiteralIntegerLiteralNCNameQNameURIQualifiedName

non-trivial

A construct is said to be a non-trivial instance of a grammatical production if it is not also an instance of one of its sub-productions.

numeric

The type xs:numeric is defined as a union type with member types xs:double, xs:float, and xs:decimal. An item that is an instance of any of these types is referred to as a numeric value, and a type that is a subtype of xs:numeric is referred to as a numeric type.

numeric predicate

A predicate whose predicate expression returns a value of type xs:numeric+ is called a numeric predicate.

option declaration

An option declaration declares an option that affects the behavior of a particular implementation. Each option consists of an identifying EQName and a StringLiteral.

ordinary production rule

An ordinary production rule is a production rule in A.1 EBNF that is not annotated ws:explicit.

or expression

An or expression is a non-trivial instance of the production OrExpr.

output declaration

An output declaration is an option declaration in the namespace http://www.w3.org/2010/xslt-xquery-serialization; it is used to declare serialization parameters.

partial function application

A static or dynamic function call is a partial function application if one or more arguments is an ArgumentPlaceholder.

partially applied function

A partially applied function is a function created by partial function application.

path expression

A path expression is either an absolute path expression or a relative path expression

pattern-separator

pattern-separator(M) is a character used to separate positive and negative sub-pictures in a picture string; the default value is U+003B (SEMICOLON, ;) .

percent

percent(M, R) is used to indicate that the number is written as a per-hundred fraction; the default value for both the marker and the rendition is U+0025 (PERCENT SIGN, %) .

per-mille

per-mille(M, R) is used to indicate that the number is written as a per-thousand fraction; the default value for both the marker and the rendition is U+2030 (PER MILLE SIGN, ) .

pipeline operator

The pipeline operator-> evaluates an expression and binds the result to the context value before evaluating another expression.

positional variable

A positional variable is a variable that is preceded by the keyword at.

pragma

A pragma is denoted by the delimiters (# and #), and consists of an identifying EQName followed by implementation-defined content.

predefined entity reference

A predefined entity reference is a short sequence of characters, beginning with an ampersand, that represents a single character that might otherwise have syntactic significance.

predicate truth value

The predicate truth value of a value $V is the result of the expression if ($V instance of xs:numeric+) then ($V = position()) else fn:boolean($V).

primary expression

A primary expression is an instance of the production PrimaryExpr. Primary expressions are the basic primitives of the language. They include literals, variable references, context value references, constructors, and function calls. A primary expression may also be created by enclosing any expression in parentheses, which is sometimes helpful in controlling the precedence of operators.

principal node kind

Every axis has a principal node kind. If an axis can contain elements, then the principal node kind is element; otherwise, it is the kind of nodes that the axis can contain.

private function

A private function is a function with a %private annotation. A private function is hidden from module import, which can not import it into the statically known function definitions of another module.

private item type

A private item type is a named item type with a %private annotation. A private item type is hidden from module import, which can not import it into the in-scope named item types of another module.

private variable

A private variable is a variable with a %private annotation. A private variable is hidden from module import, which can not import it into the in-scope variables of another module.

Prolog

A Prolog is a series of declarations and imports that define the processing environment for the module that contains the Prolog.

public function

A public function is a function without a %private annotation. A public function is accessible to module import, which can import it into the statically known function definitions of another module.

public item type

A public item type is an item type declaration without a %private annotation. A public item type is accessible to module import, which can import it into the in-scope named item types of another module.

public variable

A public variable is a variable without a %private annotation. A public variable is accessible to module import, which can import it into the in-scope variables of another module. Using %public and %private annotations in a main module is not an error, but it does not affect module imports, since a main module cannot be imported. It is a static error [err:XQST0116] if a variable declaration contains both a %private and a %public annotation, more than one %private annotation, or more than one %public annotation.

pure union type

A pure union type is a simple type that satisfies the following constraints: (a) {variety}XS11-1 is union, (b) the {facets}XS11-1 property is empty, (c) no type in the transitive membership of the union type has {variety}XS11-1list, and (d) no type in the transitive membership of the union type is a type with {variety}XS11-1union having a non-empty {facets}XS11-1 property

query

A query consists of one or more modules.

query body

The Query Body, if present, consists of an expression that defines the result of the query.

range expression

A range expression is a non-trivial instance of the production RangeExpr. A range expression is used to construct a sequence of integers.

relative path expression

A relative path expression is a non-trivial instance of the production RelativePathExpr: it consists of two or more operand expressions separated by / or // operators.

reserved namespaces

A reserved namespace is a namespace that must not be used in the name of a function declaration.

resolve

To resolve a relative URI$rel against a base URI $base is to expand it to an absolute URI, as if by calling the function fn:resolve-uri($rel, $base).

reverse document order

The node ordering that is the reverse of document order is called reverse document order.

same key

Two atomic items K1 and K2 have the same key value if fn:atomic-equal(K1, K2) returns true, as specified in [Functions and Operators 4.0] section 2.2.1 fn:atomic-equal

schema aware feature

The Schema Aware Feature permits the query Prolog to contain a schema import, and permits a query to contain a validate expression (see 4.25 Validate Expressions).

schema import

A schema import imports the element declarations, attribute declarations, and type definitions from a schema into the in-scope schema definitions. For each named user-defined simple type in the schema, schema import also adds a corresponding constructor function.

schema type

A schema type is a complex type or simple type as defined in the [XML Schema 1.0] or [XML Schema 1.1] specifications, including built-in types as well as user-defined types.

sequence

A sequence is an ordered collection of zero or more items.

sequence arrow operator

The sequence arrow operator=> applies a function to a supplied sequence.

sequence concatenation

The sequence concatenation of a number of sequences S1, S2, ... Sn is defined to be the sequence formed from the items of S1, followed by the items from S2, and so on, retaining order.

sequence expression

A sequence expression is a non-trivial instance of the production rule Expr, that is, an expression containing two or more instances of the production ExprSingle separated by the comma operator.

sequence type

A sequence type is a type that can be expressed using the SequenceType syntax. Sequence types are used whenever it is necessary to refer to a type in an XQuery 4.0 expression. Since all values are sequences, every value matches one or more sequence types.

sequence type designator

A sequence type designator is a syntactic construct conforming to the grammar rule SequenceType. A sequence type designator is said to designate a sequence type.

SequenceType matching

SequenceType matching compares a value with an expected sequence type.

serialization

Serialization is the process of converting an XDM instance to a sequence of octets (step DM4 in Figure 1.), as described in [Serialization 4.0].

serialization feature

The Serialization Feature provides means for serializing the result of a query as specified in 2.3.5 Serialization.

setter

Setters are declarations that set the value of some property that affects query processing, such as construction mode or default collation.

should

SHOULD means that there may exist valid reasons in particular circumstances to ignore a particular item, but the full implications must be understood and carefully weighed before choosing a different course.

singleton

A sequence containing exactly one item is called a singleton.

singleton enumeration type

An enumeration type with a single enumerated value E (such as enum("red")) matches an item S if and only if (a) S is an instance of xs:string, and (b) S is equal to E when compared using Unicode codepoint collation. This is referred to as a singleton enumeration type.

singleton focus

A singleton focus is a fixed focus in which the context value is a singleton item.

stable

Document order is stable, which means that the relative order of two nodes will not change during the processing of a given query , even if this order is implementation-dependent.

statically known collations

Statically known collations. This is an implementation-defined mapping from URI to collation. It defines the names of the collations that are available for use in processing queries and expressions.

statically known decimal formats

Statically known decimal formats. This is a mapping from QNames to decimal formats, with one default format that has no visible name, referred to as the unnamed decimal format. Each format is available for use when formatting numbers using the fn:format-number function.

statically known function definitions

Statically known function definitions. This is a set of function definitions.

statically known namespaces

Statically known namespaces. This is a mapping from prefix to namespace URI that defines all the namespaces that are known during static processing of a given expression.

static analysis phase

The static analysis phase depends on the expression itself and on the static context. The static analysis phase does not depend on input data (other than schemas).

Static Base URI

Static Base URI. This is an absolute URI, used to resolve relative URIs during static analysis.

static context

The static context of an expression is the information that is available during static analysis of the expression, prior to its evaluation.

static error

An error that can be detected during the static analysis phase, and is not a type error, is a static error.

static function call

A static function call is an instance of the production FunctionCall: it consists of an EQName followed by a parenthesized list of zero or more arguments.

static type

The static type of an expression is the best inference that the processor is able to make statically about the type of the result of the expression.

step

The operands of a path expression are conventionally referred to as steps.

string constructor

A string constructor is an instance of the production StringConstructor: it is an expression that creates a string from literal text and interpolated subexpressions.

string value

The string value of a node is a string and can be extracted by applying the string function to the node.

substantively disjoint

Two sequence types are deemed to be substantively disjoint if (a) neither is a subtype of the other (see 3.3.1 Subtypes of Sequence Types) and (b) the only values that are instances of both types are one or more of the following:

substitution group

Substitution groups are defined in 2.2.2.2 Element Substitution Group XS1-1 and 2.2.2.2 Element Substitution Group XS11-1. Informally, the substitution group headed by a given element (called the head element) consists of the set of elements that can be substituted for the head element without affecting the outcome of schema validation.

subtype

Given two sequence types or item types, the rules in this section determine if one is a subtype of the other. If a type A is a subtype of type B, it follows that every value matched by A is also matched by B.

subtype substitution

The use of a value that has a dynamic type that is a subtype of the expected type is known as subtype substitution.

symbol

Each rule in the grammar defines one symbol, using the following format:

symbol ::= expression
symbol separators

Whitespace and Comments function as symbol separators. For the most part, they are not mentioned in the grammar, and may occur between any two terminal symbols mentioned in the grammar, except where that is forbidden by the /* ws: explicit */ annotation in the EBNF, or by the /* xgc: xml-version */ annotation.

system function

System functions include the functions defined in [Functions and Operators 4.0], functions defined by the specifications of a host language, constructor functions for atomic types, and any additional functions provided by the implementation. System functions are sometimes called built-in functions.

target namespace

The target namespace of a module is the namespace of the objects (such as elements or functions) that it defines.

terminal

A terminal is a symbol or string or pattern that can appear in the right-hand side of a rule, but never appears on the left-hand side in the main grammar, although it may appear on the left-hand side of a rule in the grammar for terminals.

tuple

A tuple is a set of zero or more named variables, each of which is bound to a value that is an XDM instance.

tuple stream

A tuple stream is an ordered sequence of zero or more tuples.

type annotation

Each element node and attribute node in an XDM instance has a type annotation (described in [XDM 4.0] section 4.1 Schema Information). The type annotation of a node is a reference to a schema type.

typed data feature

The Typed Data Feature permits an XDM instance to contain element node types other than xs:untyped and attributes node types other than xs:untypedAtomic.

type declaration

A variable binding may be accompanied by a type declaration, which consists of the keyword as followed by the static type of the variable, declared using the syntax in 3.1 Sequence Types.

typed value

The typed value of a node is a sequence of atomic items and can be extracted by applying the data function to the node.

type error

A type error may be raised during the static analysis phase or the dynamic evaluation phase. During the static analysis phase, a type error occurs when the static type of an expression does not match the expected type of the context in which the expression occurs. During the dynamic evaluation phase, a type error occurs when the dynamic type of a value does not match the expected type of the context in which the value occurs.

URI

Within this specification, the term URI refers to a Universal Resource Identifier as defined in [RFC3986] and extended in [RFC3987] with the new name IRI.

user-defined function

User defined functions are functions that contain a function body, which provides the implementation of the function as a content expression.

value

In the data model, a value is always a sequence.

variable declaration

A variable declaration in the XQuery prolog defines the name and static type of a variable, and optionally a value for the variable. It adds to the in-scope variables in the static context, and may also add to the variable values in the dynamic context.

variable reference

A variable reference is an EQName preceded by a $-sign.

variable terminal

A variable terminal is an instance of a production rule that is not itself an ordinary production rule but that is named (directly) on the right-hand side of an ordinary production rule.

variable values

Variable values. This is a mapping from expanded QNames to values. It contains the same expanded QNames as the in-scope variables in the static context for the expression. The expanded QName is the name of the variable and the value is the dynamic value of the variable, which includes its dynamic type.

version declaration

A version declaration can identify the applicable XQuery syntax and semantics for a module, as well as its encoding.

warning

In addition to static errors, dynamic errors, and type errors, an XQuery 4.0 implementation may raise warnings, either during the static analysis phase or the dynamic evaluation phase. The circumstances in which warnings are raised, and the ways in which warnings are handled, are implementation-defined.

whitespace

A whitespace character is any of the characters defined by [http://www.w3.org/TR/REC-xml/#NT-S].

wildcard-matches

In these rules, if MU and NU are NameTestUnions, then MUwildcard-matchesNU is true if every name that matches MU also matches NU.

window

A window is a sequence of consecutive items drawn from the binding sequence.

XDM instance

The term XDM instance is used, synonymously with the term value, to denote an unconstrained sequence of items.

XNode

An XNode is an instance of one of the node kinds defined in [XDM 4.0] section 7.1 XML Nodes.

XPath 1.0 compatibility mode

XPath 1.0 compatibility mode.This component must be set by all host languages that include XPath 3.1 as a subset, indicating whether rules for compatibility with XPath 1.0 are in effect. XQuery sets the value of this component to false.

XQuery 1.0 Processor

An XQuery 1.0 Processor processes a query according to the XQuery 1.0 specification.

XQuery 3.0 Processor

An XQuery 3.0 Processor processes a query according to the XQuery 3.0 specification.

XQuery 3.1 Processor

An XQuery 3.1 Processor processes a query according to the XQuery 3.1 specification.

XQuery 4.0 Processor

An XQuery 4.0 Processor processes a query according to the XQuery 4.0 specification.

XQuery version number

An XQuery version number consists of two integers, referred to as the major version number and the minor version number.

xs:anyAtomicType

xs:anyAtomicType is an atomic type that includes all atomic items (and no values that are not atomic). Its base type is xs:anySimpleType from which all simple types, including atomic, list, and union types, are derived. All primitive atomic types, such as xs:decimal and xs:string, have xs:anyAtomicType as their base type.

xs:dayTimeDuration

xs:dayTimeDuration is derived by restriction from xs:duration. The lexical representation of xs:dayTimeDuration is restricted to contain only day, hour, minute, and second components.

xs:error

xs:error is a simple type with no value space. It is defined in 3.16.7.3 xs:error XS11-1 and can be used in the 3.1 Sequence Types to raise errors.

xs:untyped

xs:untyped is used as the type annotation of an element node that has not been validated, or has been validated in skip mode.

xs:untypedAtomic

xs:untypedAtomic is an atomic type that is used to denote untyped atomic data, such as text that has not been assigned a more specific type.

xs:yearMonthDuration

xs:yearMonthDuration is derived by restriction from xs:duration. The lexical representation of xs:yearMonthDuration is restricted to contain only year and month components.

XTree

A tree that is rooted at a parentless XNode is referred to as an XTree.

zero-digit

zero-digit(M) is the character used in the picture string to represent the digit zero; the default value is U+0030 (DIGIT ZERO, 0) . This character must be a digit (category Nd in the Unicode property database), and it must have the numeric value zero. This property implicitly defines the ten Unicode characters that are used to represent the values 0 to 9 in the function output: Unicode is organized so that each set of decimal digits forms a contiguous block of characters in numerical sequence. Within the picture string any of these ten character can be used (interchangeably) as a place-holder for a mandatory digit. Within the final result string, these ten characters are used to represent the digits zero to nine.

J Change Log (Non-Normative)

  1. Use the arrows to browse significant changes since the 3.1 version of this specification.

    See 1 Introduction

  2. Sections with significant changes are marked Δ in the table of contents.

    See 1 Introduction

  3. PR 691 2154 

    Enumeration types are added as a new kind of ItemType, constraining the value space of strings.

    See 3.2.6 Enumeration Types

  4. Setting the default namespace for elements and types to the special value ##any causes an unprefixed element name to act as a wildcard, matching by local name regardless of namespace.

    See 3.2.7.2 Element Types

  5. The terms FunctionType, ArrayType, MapType, and RecordType replace FunctionTest, ArrayTest, MapTest, and RecordTest, with no change in meaning.

    See 3.2.8.1 Function Types

  6. Record types are added as a new kind of ItemType, constraining the value space of maps.

    See 3.2.8.3 Record Types

  7. Function coercion now allows a function with arity N to be supplied where a function of arity greater than N is expected. For example this allows the function true#0 to be supplied where a predicate function is required.

    See 3.4.3 Function Coercion

  8. The symbols × and ÷ can be used for multiplication and division.

    See 4.8 Arithmetic Expressions

  9. PR 1480 1989 

    When the element name matches a language keyword such as div or value, it must now be written as a QName literal. This is a backwards incompatible change.

    See 4.12.3.1 Computed Element Constructors

    When the attribute name matches a language keyword such as by or of, it must now be written as a QName literal. This is a backwards incompatible change.

    See 4.12.3.2 Computed Attribute Constructors

  10. PR 1513 2028 

    When the processing instruction name matches a language keyword such as try or validate, it must now be written with a preceding # character. This is a backwards incompatible change.

    See 4.12.3.5 Computed Processing Instruction Constructors

    When the namespace prefix matches a language keyword such as as or at, it must now be written with a preceding # character. This is a backwards incompatible change.

    See 4.12.3.7 Computed Namespace Constructors

  11. PR 1763 1830 

    The syntax on the right-hand side of an arrow operator has been relaxed; a dynamic function call no longer needs to start with a variable reference or a parenthesized expression, it can also be (for example) an inline function expression or a map or array constructor.

    See 4.24 Arrow Expressions

  12. The arrow operator => is now complemented by a “mapping arrow” operator =!> which applies the supplied function to each item in the input sequence independently.

    See 4.24.2 Mapping Arrow Expressions

  13. All implementations must now predeclare the namespace prefixes math, map, array, and err. In XQuery 3.1 it was permitted but not required to predeclare these namespaces.

    See 5.13 Namespace Declaration

  14. PR 2200 2236 

    The effect of not declaring a default function namespace has changed: user-defined functions can now be in no namespace, and a search for an unprefixed function name will be resolved first against functions in no namespace, and only then against functions in the standard function namespace.

    See 5.14 Default Namespace Declaration

  15. PR 254 2050 

    The supplied context value is now coerced to the required type specified in the main module using the coercion rules.

    See 5.17 Context Value Declaration

  16. Function definitions in the static context may now have optional parameters, provided this does not cause ambiguity across multiple function definitions with the same name. Optional parameters are given a default value, which can be any expression, including one that depends on the context of the caller (so an argument can default to the context value).

    See 5.18 Function Declarations

  17. PR 682 TODO 

    The values true() and false() are allowed in function annotations, as well as negated numeric literals and QName literals.

    See 5.18.4 Function Annotations

  18. A user-defined function whose name is given as an unprefixed QName is now in no namespace. In previous versions of the language, it represented a name in the default function namespace (which only worked if the default function namespace was explicitly set to an unreserved namespace, which was rarely done because it caused other problems).

    See 5.18 Function Declarations

    See 5.18.2 Function Names

  19. PR 1023 1128 

    It has been clarified that function coercion applies even when the supplied function item matches the required function type. This is to ensure that arguments supplied when calling the function are checked against the signature of the required function type, which might be stricter than the signature of the supplied function item.

    See 3.4.3 Function Coercion

  20. A dynamic function call can now be applied to a sequence of functions, and in particular to an empty sequence. This makes it easier to chain a sequence of calls.

    See 4.5.3.1 Evaluating Dynamic Function Calls

  21. Parts of the static context that were there purely to assist in static typing, such as the statically known documents, were no longer referenced and have therefore been dropped.

    See B.1 Static Context Components

  22. The syntax document-node(N), where N is a NameTestUnion, is introduced as an abbreviation for document-node(element(N)). For example, document-node(*) matches any well-formed XML document (as distinct from a document fragment).

    See 3.2.7 Node Types

  23. QName literals are new in 4.0.

    See 4.2.1.3 QName Literals

  24. Path expressions are extended to handle JNodes (found in trees of maps and arrays) as well as XNodes (found in trees representing parsed XML).

    See 4.6 Path Expressions

  25. A method call invokes a function held as the value of an entry in a map, supplying the map implicitly as the value of the first argument.

    See 4.14.4 Method Calls

  26. The treat as expression now raises a type error rather than a dynamic error when it fails.

    See 4.21.6 Treat

  27. PR 159 

    Keyword arguments are allowed on static function calls, as well as positional arguments.

    See 4.5.1.1 Static Function Call Syntax

  28. PR 202 

    The presentation of the rules for the subtype relationship between sequence types and item types has been substantially rewritten to improve clarity; no change to the semantics is intended.

    See 3.3 Subtype Relationships

  29. PR 230 

    The rules for “errors and optimization” have been tightened up to disallow many cases of optimizations that alter error behavior. In particular there are restrictions on reordering the operands of and and or, and of predicates in filter expressions, in a way that might allow the processor to raise dynamic errors that the author intended to prevent.

    See 2.4.5 Guarded Expressions

    See 4.11 Logical Expressions

  30. PR 254 

    The term "function conversion rules" used in 3.1 has been replaced by the term "coercion rules".

    See 3.4 Coercion Rules

    The coercion rules allow “relabeling” of a supplied atomic item where the required type is a derived atomic type: for example, it is now permitted to supply the value 3 when calling a function that expects an instance of xs:positiveInteger.

    See 3.4 Coercion Rules

    The value bound to a variable in a let clause is now converted to the declared type by applying the coercion rules.

    See 4.13.3 Let Clause

    The coercion rules are now used when binding values to variables (both global variable declarations and local variable bindings). This aligns XQuery with XSLT, and means that the rules for binding to variables are the same as the rules for binding to function parameters.

    See 5.16 Variable Declaration

  31. PR 284 

    Alternative syntax for conditional expressions is available: if (condition) { X }.

    See 4.16 Conditional Expressions

  32. PR 286 

    Element and attribute tests can include alternative names: element(chapter|section), attribute(role|class).

    See 3.2.7 Node Types

    The NodeTest in an AxisStep now allows alternatives: ancestor::(section|appendix)

    See 3.2.7 Node Types

    Element and attribute tests of the form element(N) and attribute(N) now allow N to be any NameTest, including a wildcard.

    See 3.2.7.2 Element Types

    See 3.2.7.3 Attribute Types

  33. PR 324 

    String templates provide a new way of constructing strings: for example `{$greeting}, {$planet}!` is equivalent to $greeting || ', ' || $planet || '!'

    See 4.9.2 String Templates

  34. PR 326 

    Support for higher-order functions is now a mandatory feature (in 3.1 it was optional).

    See 6 Conformance

  35. PR 344 

    A for member clause is added to FLWOR expressions to allow iteration over an array.

    See 4.13.2 For Clause

  36. PR 364 

    Switch expressions now allow a case clause to match multiple atomic items.

    See 4.18 Switch Expressions

  37. PR 368 

    The concept of the context item has been generalized, so it is now a context value. That is, it is no longer constrained to be a single item.

    See 2.2.2 Dynamic Context

    See 5.17 Context Value Declaration

  38. PR 433 

    Numeric literals can now be written in hexadecimal or binary notation; and underscores can be included for readability.

    See 4.2.1.1 Numeric Literals

  39. PR 483 

    The start clause in window expressions has become optional, as well as the when keyword and its associated expression.

    See 4.13.4 Window Clause

  40. PR 487 

    In XQuery 4.0, an initial set of namespace bindings is prescribed for the static context.

    See 2.1.4 Namespaces and QNames

  41. PR 493 

    A new variable $err:map is available, capturing all error information in one place.

    See 4.20 Try/Catch Expressions

  42. PR 519 

    The rules for tokenization have been largely rewritten. In some cases the revised specification may affect edge cases that were handled in different ways by different 3.1 processors, which could lead to incompatible behavior.

    See A.3 Lexical structure

  43. PR 521 

    New abbreviated syntax is introduced (focus function) for simple inline functions taking a single argument. An example is fn { ../@code }

    See 4.5.6 Inline Function Expressions

  44. PR 587 

    Switch and typeswitch expressions can now be written with curly brackets, to improve readability.

    See 4.18 Switch Expressions

    See 4.21.2 Typeswitch

  45. PR 603 

    The rules for reporting type errors during static analysis have been changed so that a processor has more freedom to report errors in respect of constructs that are evidently wrong, such as @price/@value, even though dynamic evaluation is defined to return an empty sequence rather than an error.

    See 2.4.6 Implausible Expressions

    See 4.6.4.6 Implausible Axis Steps

  46. PR 606 

    Element and attribute tests of the form element(A|B) and attribute(A|B) are now allowed.

    See 3.2.7.2 Element Types

    See 3.2.7.3 Attribute Types

  47. PR 635 

    The rules for the consistency of schemas imported by different query modules, and for consistency between imported schemas and those used for validating input documents, have been defined with greater precision. It is now recognized that these schemas will not always be identical, and that validation with respect to different schemas may produce different outcomes, even if the components of one are a subset of the components of the other.

    See 5.11 Schema Import

  48. PR 659 

    In previous versions the interpretation of location hints in import schema declarations was entirely at the discretion of the processor. To improve interoperability, XQuery 4.0 recommends (but does not mandate) a specific strategy for interpreting these hints.

    See 5.11 Schema Import

  49. PR 678 

    The comparand expression in a switch expression can be omitted, allowing the switch cases to be provided as arbitrary boolean expressions.

    See 4.18 Switch Expressions

  50. PR 728 

    The syntax record(*) is allowed; it matches any map.

    See 3.2.8.3 Record Types

  51. PR 753 

    The default namespace for elements and types can now be declared to be fixed for a query module, meaning it is unaffected by a namespace declaration appearing on a direct element constructor.

    See 4.12.1.2 Namespace Declaration Attributes

    See 5.14 Default Namespace Declaration

  52. PR 815 

    The coercion rules now allow conversion in either direction between xs:hexBinary and xs:base64Binary.

    See 3.4 Coercion Rules

  53. PR 820 

    The value bound to a variable in a for clause is now converted to the declared type by applying the coercion rules.

    See 4.13.2 For Clause

  54. PR 911 

    The coercion rules now allow any numeric type to be implicitly converted to any other, for example an xs:double is accepted where the required type is xs:decimal.

    See 3.4 Coercion Rules

  55. PR 943 

    A FLWOR expression may now include a while clause, which causes early exit from the iteration when a condition is encountered.

    See 4.13.6 While Clause

  56. PR 996 

    The value of a predicate in a filter expression can now be a sequence of integers.

    See 4.4 Filter Expressions

  57. PR 1031 

    An otherwise operator is introduced: A otherwise B returns the value of A, unless it is an empty sequence, in which case it returns the value of B.

    See 4.17 Otherwise Expressions

  58. PR 1071 

    In map constructors, the keyword map is now optional, so map { 0: false(), 1: true() } can now be written { 0: false(), 1: true() }, provided it is used in a context where this creates no ambiguity.

    See 4.14.1.1 Map Constructors

  59. PR 1132 

    Choice item types (an item type allowing a set of alternative item types) are introduced.

    See 3.2.5 Choice Item Types

  60. PR 1163 

    Filter expressions for maps and arrays are introduced.

    See 4.14.5 Filter Expressions for Maps and Arrays

  61. PR 1181 

    The default namespace for elements and types can be set to the value ##any, allowing unprefixed names in axis steps to match elements with a given local name in any namespace.

    See 2.2.1 Static Context

    If the default namespace for elements and types has the special value ##any, then an unprefixed name in a NameTest acts as a wildcard, matching names in any namespace or none.

    See 4.6.4.2 Node Tests

    The default namespace for elements and types can be set to the value ##any, allowing unprefixed names in axis steps to match elements with a given local name in any namespace.

    See 5.14 Default Namespace Declaration

  62. PR 1197 

    The keyword fn is allowed as a synonym for function in function types, to align with changes to inline function declarations.

    See 3.2.8.1 Function Types

    In inline function expressions, the keyword function may be abbreviated as fn.

    See 4.5.6 Inline Function Expressions

  63. PR 1212 

    New keywords introducing item types, such as record, item, and enum, have been added to the list of reserved function names.

    See A.4 Reserved Function Names

  64. PR 1217 

    Predicates in filter expressions for maps and arrays can now be numeric.

    See 4.14.5 Filter Expressions for Maps and Arrays

  65. PR 1249 

    A for key/value clause is added to FLWOR expressions to allow iteration over a map.

    See 4.13.2 For Clause

  66. PR 1250 

    Several decimal format properties, including minus sign, exponent separator, percent, and per-mille, can now be rendered as arbitrary strings rather than being confined to a single character.

    See 2.2.1.2 Decimal Formats

    See 5.10 Decimal Format Declaration

  67. PR 1254 

    The rules concerning the interpretation of xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes have been tightened up.

    See 4.25 Validate Expressions

  68. PR 1265 

    The rules regarding the document-uri property of nodes returned by the fn:collection function have been relaxed.

    See 2.2.2 Dynamic Context

  69. PR 1342 

    The ordered { E } and unordered { E } expressions are retained for backwards compatibility reasons, but in XQuery 4.0 they are deprecated and have no useful effect.

    See 4.15 Ordered and Unordered Expressions

    The ordering mode declaration is retained for backwards compatibility reasons, but in XQuery 4.0 it is deprecated and has no useful effect.

    See 5.7 Ordering Mode Declaration

  70. PR 1344 

    Parts of the static context that were there purely to assist in static typing, such as the statically known documents, were no longer referenced and have therefore been dropped.

    See 2.2.1 Static Context

    The static typing option has been dropped.

    See 2.3 Processing Model

    The static typing feature has been dropped.

    See 6 Conformance

  71. PR 1361 

    The term atomic value has been replaced by atomic item.

    See 2.1.3 Values

  72. PR 1384 

    If a type declaration is present, the supplied values in the input sequence are now coerced to the required type. Type declarations are now permitted in XPath as well as XQuery.

    See 4.19 Quantified Expressions

  73. PR 1432 

    In earlier versions, the static context for the initializing expression excluded the variable being declared. This restriction has been lifted.

    See 5.16 Variable Declaration

  74. PR 1470 

    $err:stack-trace provides information about the current state of execution.

    See 4.20 Try/Catch Expressions

  75. PR 1496 

    The context value static type, which was there purely to assist in static typing, has been dropped.

    See 2.2.1 Static Context

  76. PR 1498 

    The EBNF operators ++ and ** have been introduced, for more concise representation of sequences using a character such as "," as a separator. The notation is borrowed from Invisible XML.

    See 2.1 Terminology

    The EBNF notation has been extended to allow the constructs (A ++ ",") (one or more occurrences of A, comma-separated, and (A ** ",") (zero or more occurrences of A, comma-separated.

    See 2.1.1 Grammar Notation

    The EBNF operators ++ and ** have been introduced, for more concise representation of sequences using a character such as "," as a separator. The notation is borrowed from Invisible XML.

    See A.1 EBNF

    See A.1.1 Notation

  77. PR 1501 

    The coercion rules now apply recursively to the members of an array and the entries in a map.

    See 3.4 Coercion Rules

  78. PR 1532 

    Four new axes have been defined: preceding-or-self, preceding-sibling-or-self, following-or-self, and following-sibling-or-self.

    See 4.6.4.1 Axes

  79. PR 1577 

    The syntax record() is allowed; the only thing it matches is an empty map.

    See 3.2.8.3 Record Types

  80. PR 1686 

    With the pipeline operator ->, the result of an expression can be bound to the context value before evaluating another expression.

    See 4.22 Pipeline operator

  81. PR 1696 

    Parameter names may be included in a function signature; they are purely documentary.

    See 3.2.8.1 Function Types

  82. PR 1703 

    Ordered maps are introduced.

    See 4.14.1 Maps

    The order of key-value pairs in the map constructor is now retained in the constructed map.

    See 4.14.1.1 Map Constructors

  83. PR 1874 

    The coercion rules now reorder the entries in a map when the required type is a record type.

    See 3.4 Coercion Rules

  84. PR 1898 

    The rules for subtyping of document node types have been refined.

    See 3.3.2.5.2 Subtyping Nodes: Document Nodes

  85. PR 1914 

    A finally clause can be supplied, which will always be evaluated after the expressions of the try/catch clauses.

    See 4.20 Try/Catch Expressions

  86. PR 1956 

    Private variables declared in a library module are no longer required to be in the module namespace.

    See 5.16 Variable Declaration

    Private functions declared in a library module are no longer required to be in the module namespace.

    See 5.18.2 Function Names

  87. PR 1982 

    Whitespace is now required after the opening (# of a pragma. This is an incompatible change, made to ensure that an expression such as error(#err:XPTY0004) can be parsed as a function call taking a QName literal as its argument value.

    See 4.26 Extension Expressions

  88. PR 1991 

    Named record types used in the signatures of built-in functions are now available as standard in the static context.

    See 2.2.1 Static Context

  89. PR 2026 

    The module feature is no longer an optional feature; processing of library modules is now required.

    See 6 Conformance

  90. PR 2030 

    The technical details of how validation works have been moved to the Functions and Operators specification. The XQuery validate expression is now defined in terms of the new xsd-validator function.

    See 4.25 Validate Expressions

  91. PR 2031 

    The terms XNode and JNode are introduced; the existing term node remains in use as a synonym for XNode where the context does not specify otherwise.

    See 2.1.3 Values

    JNodes are introduced

    See 3.2.9 Generalized Node Types

  92. PR 2055 

    Sequences, arrays, and maps can be destructured in a let clause to extract their components into multiple variables.

    See 4.13.3 Let Clause

  93. PR 2094 

    A general expression is allowed within a map constructor; this facilitates the creation of maps in which the presence or absence of particular keys is decided dynamically.

    See 4.14.1.1 Map Constructors

  94. PR 2115 

    This section describes and formalizes a convention that was already in use, but not explicitly stated, in earlier versions of the specification.

    See 2.1.2 Expression Names

  95. PR 2130 

    Operator is-not is introduced, as a complement to the operator is.

    See 4.10.3 GNode Comparisons

    Operators precedes and follows are introduced as synonyms for operators << and >>.

    See 4.10.3 GNode Comparisons

    Operators precedes-or-is and follows-or-is are introduced as synonyms for the union of operators << and is and for the union of operators >> and is, respectively.

    See 4.10.3 GNode Comparisons

  96. PR 2134 

    The lookup operator ? can now be followed by an arbitrary literal, for cases where keys are items other than integers or NCNames. It can also be followed by a variable reference or a context value reference.

    See 4.14.3 Lookup Expressions

  97. PR 2200 

    The effect of not declaring a default function namespace has changed: user-defined functions can now be in no namespace, and a search for an unprefixed function name will be resolved first against functions in no namespace, and only then against functions in the standard function namespace.

    See 5.14 Default Namespace Declaration

  98. PR 2202 

    The type schema-element(N) is now defined to be a subtype of element() and of various other element tests.

    See 3.3.2.5.3 Subtyping Nodes: Elements

    The type schema-attribute(N) is now defined to be a subtype of attribute() and of various other attribute tests.

    See 3.3.2.5.4 Subtyping Nodes: Attributes

  99. PR 2218 

    The rules for value comparisons when comparing values of different types (for example, decimal and double) have changed to be transitive. A decimal value is no longer converted to double, instead the double is converted to a decimal without loss of precision. This may affect compatibility in edge cases involving comparison of values that are numerically very close.

    See 4.10.1 Value Comparisons

    The rules for comparing untyped atomic values with numeric values have changed. Rather than converting an untyped atomic value unconditionally to xs:double, it is now converted to the type of the numeric operand. This is designed to ensure that comparisons such as <a>1.1</a> = 1.1 succeed, given that the values will now be compared as decimals rather than as doubles.

    See 4.10.2 General Comparisons