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.
Copyright © 2000 W3C® (MIT, ERCIM, Keio, Beihang). W3C liability, trademark and document use rules apply.
XPath 4.0 is an expression language that allows the processing of values conforming to the data model defined in [XDM 4.0]. The name of the language derives from its most distinctive feature, the path expression, which provides a means of hierarchic addressing of the nodes in an XML tree. As well as modeling the tree structure of XML, the data model also includes atomic items, function items, maps, arrays, and sequences. This version of XPath supports JSON as well as XML, and adds many new functions in [Functions and Operators 4.0].
XPath 4.0 is a superset of XPath 3.1. A detailed list of changes made since XPath 3.1 can be found in I Change Log.
This is a draft prepared by the QT4CG (officially registered in W3C as the XSLT Extensions Community Group). Comments are invited.
The publications of this community group are dedicated to our co-chair, Michael Sperberg-McQueen (1954–2024).
Michael was central to the development of XML and many related technologies. He brought a polymathic breadth of knowledge and experience to everything he did. This, combined with his indefatigable curiosity and appetite for learning, made him an invaluable contributor to our project, along with many others. We have lost a brilliant thinker, a patient teacher, and a loyal friend.
[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.
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]
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]
The context value static type, which was there purely to assist in static typing, has been dropped. [Issue 1495 PR 1496 29 October 2024]
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 XPath 4.0, the static context for an expression is largely defined by the host language, that is, by the calling environment that causes an XPath expression to be evaluated. Most of the static context components are constant throughout an expression; the only exception is in-scope variables. (There are constructs in the language, such as the ForExpr and LetExpr, that add additional variables to the static context of their subexpressions.)
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 value is true if rules for backward compatibility with XPath Version 1.0 are in effect; otherwise it is 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.
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.
[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:
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.
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.
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.
[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. ]
[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). ] 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). ]
[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.]
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, the in-scope variables are extended by the names and types of the function parameters.
[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:
Named item types can be defined in a host language such as XQuery 4.0 and in XSLT 4.0, but not in XPath 4.0 itself. They are available in XPath only if the host language provides the ability to define them.
[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 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: 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. If E is a subexpression of F then the Static Base URI of E is the same as the Static Base URI of F. There are no constructs in XPath that require resolution of relative URI references during static analysis.
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.
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 XPath 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 XPath 4.0 Grammar].
The highest-level symbol in the XPath grammar is XPath.
XPath | ::= | (DefaultElementNamespaceDecl ";")? (NamespaceDecl ";")* Expr |
DefaultElementNamespaceDecl | ::= | "declare" "default" "element" "namespace" URILiteral |
NamespaceDecl | ::= | "declare" "namespace" NCName "=" URILiteral |
Expr | ::= | (ExprSingle ++ ",") |
The effect of a DefaultElementNamespaceDecl or NamespaceDecl is described in 4.1 Namespace Declarations.
ExprSingle | ::= | ForExpr |
ForExpr | ::= | ForClauseForLetReturn |
LetExpr | ::= | LetClauseForLetReturn |
QuantifiedExpr | ::= | ("some" | "every") (QuantifierBinding ++ ",") "satisfies" ExprSingle |
IfExpr | ::= | "if" "(" Expr ")" (UnbracedActions | BracedAction) |
OrExpr | ::= | AndExpr ("or" AndExpr)* |
The XPath 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 ForExpr, LetExpr, QuantifiedExpr, IfExpr, and OrExpr. Each of these expressions is described in a separate section of this document.
Functions in XPath 4.0 arise in two ways:
A function definition contains information about a family of functions with the same name and a defined arity range. These functions are in most cases known statically (they appear in the statically known function definitions), but there may be further function definitions that are known only dynamically (appearing in the dynamically known function definitions).
Function items are XDM items that can be called using a dynamic function call. They are values that can be bound to variables, passed as arguments, returned as function results, and generally manipulated in the same way as other XDM values.
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.
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.6.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.
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.
An and expression is a non-trivial instance of the production AndExpr.
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 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.
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).
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.
An array is a function item that associates a set of positions, represented as positive integer keys, with values.
The value associated with a given key is called the associated value of the key.
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].
An atomic type is a simple schema type whose {variety}XS11-1 is atomic.
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. 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. 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 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. 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. 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.
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.
The result of evaluating the binding expression in a for expression is called the binding collection
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.
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.
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.
A comma operator is a comma used specifically as the operator in a sequence expression.
A complex terminal is a variable terminal whose production rule references, directly or indirectly, an ordinary production rule.
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?.
In an enclosed expression, the optional expression enclosed in curly brackets is called the content expression.
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.
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.
The context position is the position of the context value within the series of values currently being processed.
The context size is the number of values in the series of values currently being processed.
The context value is the value currently being processed.
Current dateTime. This information represents an implementation-dependent point in time during the processing of an expression, and includes an explicit timezone. It can be retrieved by the fn:current-dateTime function. If called multiple times during the execution of an expression, this function always returns the same result.
XPath 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-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 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. 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 collection. This is the sequence of items that would result from calling the fn:collection function with no arguments.
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. This determines how unprefixed lexical QNames appearing in static functiona static function call calls or named functionor a named function reference references are interpreted.
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.
The default in-scope namespace of an element node
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. 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 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.
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. This is the sequence of URIs that would result from calling the fn:uri-collection function with no arguments.
The delimiting terminal symbols are: !!=#$()**:+,-->...///::*:::=;<<<<===!>=>=?>>>=>>??[@[]```{{{|||}}}×÷AposStringLiteralBracedURILiteralQuotStringLiteralStringLiteral
A schema typeS1 is said to derive fromschema typeS2 if any of the following conditions is true:
S1 is the same type as S2.
S2 is the base type of S1.
S2 is a pure union type of which S1 is a member type.
There is a schema typeM such that S1derives fromM and Mderives fromS2.
digit(M) is a character used in the picture string to represent an optional digit; the default value is U+0023 (NUMBER SIGN, #) .
Informally, document order is the order in which nodes appear in the XML serialization of a document.
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.
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.
A dynamic error is an error that must be detected during the dynamic evaluation phase and may be detected during the static analysis phase.
The dynamic evaluation phase is the phase during which the value of an expression is computed.
is
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.
The effective boolean value of a value is defined as the result of applying the fn:boolean function to the value.
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.
A sequence containing zero items is called an empty sequence.
An enclosed expression is an instance of the EnclosedExpr production, which allows an optional expression within curly brackets.
Each key / value pair in a map is called an entry.
An EnumerationType accepts a fixed set of string values.
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.
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. 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.
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(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) .
The expression context for a given expression consists of all the information that can affect the result of the expression.
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.
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.
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.
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.
The first three components of the dynamic context (context value, context position, and context size) are called the focus of the expression.
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 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.
A function definition contains information used to evaluate a static function call, including the name, parameters, and return type of the function.
A function item is an item that can be called using a dynamic function call.
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.
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-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, ,) .
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.
A host language for XPath is any environment that provides capabilities for XPath expressions to be defined and evaluated, and that supplies a static and dynamic context for their evaluation.
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).
Certain expressions, while not erroneous, are classified as being implausible, because they achieve no useful effect.
Implementation-defined indicates an aspect that may differ between implementations, but must be specified by the implementer for each particular implementation.
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. 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(R) is the string used to represent the double value infinity (INF); the default value is the string "Infinity"
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. 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).
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).
In-scope named item types. This is a mapping from expanded QNames to named item types.
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 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 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.
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.
An item is either an atomic item, a node, or a function item.
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.
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.
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.
A tree that is rooted at a parentless JNode is referred to as a JTree.
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·
A lexical QName is a name that conforms to the syntax of the QName production
A literal is a direct syntactic representation of an atomic item.
A literal terminal is a token appearing as a string in quotation marks on the right-hand side of an ordinary production rule.
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.
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.
A map is a function that associates a set of keys with values, resulting in a collection of key / value pairs.
The mapping arrow operator=!> applies a function to each item in a sequence.
MAY means that an item is truly optional.
The values of an array are called its members.
minus-sign(R) is the string used to mark negative numbers; the default value is U+002D (HYPHEN-MINUS, -) .
MUST means that the item is an absolute requirement of the specification.
MUST NOT means that the item is an absolute prohibition of the specification.
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.
A named item type is an ItemType identified by an expanded QName.
A namespace binding is a pair comprising a namespace prefix (which is either an xs:NCName or empty), and a namespace URI.
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.
A node test that consists only of an EQName or a Wildcard is called a name test.
NaN(R) is the string used to represent the double value NaN (not a number); the default value is the string "NaN"
Except where the context indicates otherwise, the term node is used as a synonym for XNode.
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.
When an unprefixed lexical QName is expanded using the no-namespace rule, it is interpreted as having an absent namespace URI.
The non-delimiting terminal symbols are: ancestorancestor-or-selfandarrayasatattributecastcastablechildcommentdeclaredefaultdescendantdescendant-or-selfdivdocument-nodeelementelseempty-sequenceenumeqeveryexceptfnfollowingfollowing-or-selffollowing-siblingfollowing-sibling-or-selffollowsfollows-or-isforfunctiongegetgnodegtidivifininstanceintersectisis-notitemjnodekeyleletltmapmembermodnamespacenamespace-nodenenodeoforotherwiseparentprecedesprecedes-or-isprecedingpreceding-or-selfpreceding-siblingpreceding-sibling-or-selfprocessing-instructionrecordreturnsatisfiesschema-attributeschema-elementselfsometextthentotreattypeunionvalueBinaryIntegerLiteralDecimalLiteralDoubleLiteralHexIntegerLiteralIntegerLiteralNCNameQNameURIQualifiedName
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.
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.
An ordinary production rule is a production rule in A.1 EBNF that is not annotated ws:explicit.
An or expression is a non-trivial instance of the production OrExpr.
A static or dynamic function call is a partial function application if one or more arguments is an ArgumentPlaceholder.
A partially applied function is a function created by partial function application.
A path expression is either an absolute path expression or a relative path expression
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(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(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, ‰) .
The pipeline operator-> evaluates an expression and binds the result to the context value before evaluating another expression.
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).
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, 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.
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.
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
A range expression is a non-trivial instance of the production RangeExpr. A range expression is used to construct a sequence of integers.
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.
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).
The node ordering that is the reverse of document order is called reverse document order.
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
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.
A sequence is an ordered collection of zero or more items.
The sequence arrow operator=> applies a function to a supplied sequence.
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.
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.
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 XPath 4.0 expression. Since all values are sequences, every value matches one or more sequence types.
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 compares a value with an expected sequence type.
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].
A sequence containing exactly one item is called a singleton.
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.
A singleton focus is a fixed focus in which the context value is a singleton item.
Document order is stable, which means that the relative order of two nodes will not change during the processing of a given expression, even if this order is implementation-dependent.
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 expressions.
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. This is a set of function definitions.
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 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. This is an absolute URI, used to resolve relative URIs during static analysis.
The static context of an expression is the information that is available during static analysis of the expression, prior to its evaluation.
An error that can be detected during the static analysis phase, and is not a type error, is a static error.
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.
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.
The operands of a path expression are conventionally referred to as steps.
The string value of a node is a string and can be extracted by applying the string function to the node.
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:
The empty sequence, ().
The empty mapDM, {}.
The empty arrayDM, [].
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.
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.
The use of a value that has a dynamic type that is a subtype of the expected type is known as subtype substitution.
Each rule in the grammar defines one symbol, using the following format:
symbol ::= expression
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 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.
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.
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.
The typed value of a node is a sequence of atomic items and can be extracted by applying the data function to the node.
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.
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.
In the data model, a value is always a sequence.
A variable reference is an EQName preceded by a $-sign.
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. 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.
In addition to static errors, dynamic errors, and type errors, an XPath 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.
A whitespace character is any of the characters defined by [http://www.w3.org/TR/REC-xml/#NT-S].
In these rules, if MU and NU are NameTestUnions, then MUwildcard-matchesNU is true if every name that matches MU also matches NU.
The term XDM instance is used, synonymously with the term value, to denote an unconstrained sequence of items.
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.This value is true if rules for backward compatibility with XPath Version 1.0 are in effect; otherwise it is false.
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 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 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 is used as the type annotation of an element node that has not been validated, or has been validated in skip mode.
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 is derived by restriction from xs:duration. The lexical representation of xs:yearMonthDuration is restricted to contain only year and month components.
A tree that is rooted at a parentless XNode is referred to as an XTree.
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.