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

XML Path Language (XPath) 4.0 WG Review Draft

W3C Editor's Draft 23 February 2026

This version:
https://qt4cg.org/specifications/xpath-40/
Most recent version of XPath:
https://qt4cg.org/specifications/xpath-40/
Most recent Recommendation of XPath:
https://www.w3.org/TR/2017/REC-xpath-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

XPath 4.0 is an expression language that allows the processing of values conforming to the data model defined in [XQuery and XPath Data Model (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 [XQuery and XPath 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.

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).

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.


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 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::=Expr
Expr::=(ExprSingle ++ ",")
ExprSingle::=ForExpr| LetExpr| QuantifiedExpr| IfExpr| OrExpr
ExprSingle::=ForExpr
| LetExpr
| QuantifiedExpr
| IfExpr
| OrExpr
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.

4.2 Primary Expressions

[Definition: A primary expression is an instance of the production PrimaryExpr. Primary Expressionsexpressions 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.] Map and Array Constructors are described in 4.13.1 Maps and 4.13.2 Arrays.

PrimaryExpr::=Literal
| VarRef
| ParenthesizedExpr
| ContextValueRef
| FunctionCall
| FunctionItemExpr
| MapConstructor
| ArrayConstructor
| StringTemplate
| UnaryLookup
Literal::=NumericLiteral | StringLiteral | QNameLiteral
VarRef::="$" EQName
ParenthesizedExpr::="(" Expr? ")"
ContextValueRef::="."
FunctionCall::=EQNameArgumentList
/* xgc: reserved-function-names */
/* gn: parens */
FunctionItemExpr::=NamedFunctionRef | InlineFunctionExpr
NamedFunctionRef::=EQName "#" IntegerLiteral
/* xgc: reserved-function-names */
InlineFunctionExpr::=MethodAnnotation* ("function" | "fn") FunctionSignature? FunctionBody
MapConstructor::="map"? "{" (MapConstructorEntry ** ",") "}"
ArrayConstructor::=SquareArrayConstructor | CurlyArrayConstructor
StringTemplate::="`" (StringTemplateFixedPart | StringTemplateVariablePart)* "`"
/* ws: explicit */
UnaryLookup::=Lookup

4.2.4 Parenthesized Expressions

ParenthesizedExpr::="(" Expr? ")"
Expr::=(ExprSingle ++ ",")
ExprSingle::=ForExpr| LetExpr| QuantifiedExpr| IfExpr| OrExpr

Parentheses may be used to override the precedence rules. For example, the expression (2 + 4) * 5 evaluates to thirty, since the parenthesized expression (2 + 4) is evaluated first and its result is multiplied by five. Without parentheses, the expression 2 + 4 * 5 evaluates to twenty-two, because the multiplication operator has higher precedence than the addition operator.

Empty parentheses are used to denote an empty sequence, as described in 4.7.1 Sequence Concatenation.

4.2.5 Enclosed Expressions

EnclosedExpr::="{" Expr? "}"
Expr::=(ExprSingle ++ ",")
ExprSingle::=ForExpr| LetExpr| QuantifiedExpr| IfExpr| OrExpr

[Definition: An enclosed expression is an instance of the EnclosedExpr production, which allows an optional expression within curly brackets.] [Definition: In an enclosed expression, the optional expression enclosed in curly brackets is called the content expression.] If the content expression is not provided explicitly, the content expression is ().

Note:

Despite the name, an enclosed expression is not actually an expression in its own right; rather it is a construct that is used in the grammar of many other expressions.

4.3 Postfix Expressions

PostfixExpr::=PrimaryExpr | FilterExpr | DynamicFunctionCall | LookupExpr | FilterExprAM
PrimaryExpr::=Literal
| VarRef
| ParenthesizedExpr
| ContextValueRef
| FunctionCall
| FunctionItemExpr
| MapConstructor
| ArrayConstructor
| StringTemplate
| UnaryLookup
FilterExpr::=PostfixExprPredicate
DynamicFunctionCall::=PostfixExprPositionalArgumentList
LookupExpr::=PostfixExprLookup
FilterExprAM::=PostfixExpr "?[" Expr "]"

A postfix expression takes one of the following forms:

  • [Definition: 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 expressions are described in 4.4 Filter Expressions.

    An example of a filter expression is (1 to 100)[. mod 2 = 0] which returns all even numbers in the range 1 to 100.

    The base expression E1E1 can itself be a postfix expression, so multiple predicates are allowed, in the form E1E1[E2E2][E3E3][E4E4].

  • [Definition: is ]A dynamic function call is an instance of the construct DynamicFunctionCall: that is, it is an expression in the form E1(E2, E3, ...) in which E1 identifies a function item to be called, and the parenthesized argument list (E2, E3, ...)) identifies the arguments supplied to the function. Its effect is to evaluate E1E1 to obtain a function, and then call that function, with the values of expressions E2, E3, ... as arguments. Dynamic function calls are described in 4.5.3 Dynamic Function Calls.

    An example of a dynamic function call is $f("a", 2) where the value of variable $f must be a function item.

  • [Definition: 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.]

    Lookup expressions are described in 4.13.3.1 Postfix Lookup Expressions.

    An example of a lookup expression is $emp?name, where the value of variable $emp is a map, and the string "name" is the key of one of the entries in the map.

  • [Definition: 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.]

    Filter expressions for maps and array are described in 4.13.4 Filter Expressions for Maps and Arrays.

Postfix expressions are evaluated from left-to-right. For example, the expression $E1[E2]?(E3)(E4) is evaluated by first evaluating the filter expression $E1[E2] to produce a sequence of maps and arrays (say $S), then evaluating the lookup expression $S?(E3) to produce a function item (say $F), then evaluating the dynamic function call $F(E4) to produce the final result.

Note:

The grammar for postfix expressions is defined here in a way designed to link clearly to the semantics of the different kinds of expression. For parsing purposes, the equivalent production rule:

PostfixExpr := PrimaryExpr (Predicate | PositionalArgumentList | Lookup)*

(as used in XPath 3.1) is probably more convenient.

4.4 Filter Expressions

Changes in 4.0  

  1. The value of a predicate in a filter expression can now be a sequence of integers.   [Issue 816 PR 996 6 February 2024]

FilterExpr::=PostfixExprPredicate
PostfixExpr::=PrimaryExpr | FilterExpr | DynamicFunctionCall | LookupExpr | FilterExprAM
Predicate::="[" Expr "]"
Expr::=(ExprSingle ++ ",")
ExprSingle::=ForExpr| LetExpr| QuantifiedExpr| IfExpr| OrExpr

A filter expression consists of a base expression followed by a predicate, which is an expression written in square brackets. The result of the filter expression consists of the items returned by the base expression, filtered by applying the predicate to each item in turn. The ordering of the items returned by a filter expression is the same as their order in the result of the primary expression.

Note:

Where the expression before the square brackets is an AbbreviatedStep or FullStep, the expression is technically not a filter expression but an AxisStep. There are minor differences in the semantics: see 4.6.5 Predicates within Steps

Here are some examples of filter expressions:

  • Given a sequence of products in a variable, return only those products whose price is greater than 100.

    $products[price gt 100]
  • List all the integers from 1 to 100 that are divisible by 5. (See 4.7.1 Sequence Concatenation for an explanation of the to operator.)

    (1 to 100)[. mod 5 eq 0]
  • The result of the following expression is the integer 25:

    (21 to 29)[5]
  • The following example returns the fifth through ninth items in the sequence bound to variable $orders.

    $orders[5 to 9]
  • The following example illustrates the use of a filter expression as a step in a path expression. It returns the last chapter or appendix within the book bound to variable $book:

    $book/(chapter | appendix)[last()]

For each item in the input sequence, the predicate expression is evaluated using an inner focus, defined as follows: The context value is the item currently being tested against the predicate. The context size is the number of items in the input sequence. The context position is the position of the context value within the input sequence.

For each item in the input sequence, the result of the predicate expression is coerced to an xs:boolean value, called the predicate truth value, as described below. Those items for which the predicate truth value is true are retained, and those for which the predicate truth value is false are discarded.

[Definition: 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).]

Expanding this definition, the predicate truth value can be obtained by applying the following rules, in order:

  1. If the value V of the predicate expression is a sequence whose first item is an instance of the type xs:numeric, then:

    1. V must be an instance of the type xs:numeric+ (that is, every item in V must be numeric). A type error [err:FORG0006]FO40 is raised if this is not the case.

    2. The predicate truth value is true if V is equal (by the = operator) to the context position, and is false otherwise.

    In effect this means that an item in the input sequence is selected if its position in the sequence is equal to one or more of the numeric values in the predicate. For example, the predicate [3 to 5] is true for the third, fourth, and fifth items in the input sequence.

    Note:

    It is possible, though not generally useful, for the value of a numeric predicate to depend on the focus, and thus to differ for different items in the input sequence. For example, the predicate [xs:integer(@seq)] selects those items in the input sequence whose @seq attribute is numerically equal to their position in the input sequence.

    It is also possible, and again not generally useful, for the value of the predicate to be numeric for some items in the input sequence, and boolean for others. For example, the predicate [@special otherwise last()] is true for an item that either has an @special attribute, or is the last item in the input sequence.

    Note:

    The truth value of a numeric predicate does not depend on the order of the numbers in V. The predicates [ 1, 2, 3 ] and [ 3, 2, 1 ] have exactly the same effect. The items in the result of a filter expression always retain the ordering of the input sequence.

    Note:

    The truth value of a numeric predicate whose value is non-integral or non-positive is always false.

    Note:

    Beware that using boolean operators (and, or, not()) with numeric values may not have the intended effect. For example the predicate [1 or last()] selects every item in the sequence, because or operates on the effective boolean value of its operands. The required effect can be achieved with the predicate [1, last()].

  2. Otherwise, the predicate truth value is the effective boolean value of the predicate expression.

4.6 Path Expressions

Changes in 4.0  

  1. Path expressions are extended to handle JNodes (found in trees of maps and arrays) as well as XNodes (found in trees representing parsed XML).   [Issue 2054 ]

PathExpr::=AbsolutePathExpr
| RelativePathExpr
/* xgc: leading-lone-slash */
AbsolutePathExpr::=("/" RelativePathExpr?) | ("//" RelativePathExpr)
RelativePathExpr::=StepExpr (("/" | "//") StepExpr)*

[Definition: A path expression is either an absolute path expression or a relative path expression ]

[Definition: 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.]

[Definition: 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.]

[Definition: The operands of a path expression are conventionally referred to as steps.]

Note:

The term step must not be confused with axis step. A step can be any kind of expression, often but not necessarily an axis step, while an axis step can be used in any expression context, not necessarily as a step in a path expression.

A path expression is typically used to locate GNodes within GTrees.

Note:

Note the terminology:

The following definitions are copied from the data model specification, for convenience:

  • [Definition: A tree that is rooted at a parentless JNode is referred to as a JTree.]

  • [Definition: A tree that is rooted at a parentless XNode is referred to as an XTree.]

  • [Definition: 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.]

  • [Definition: 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.]

[Definition: The term GTree means JTree or XTree.]

Absolute path expressions (those starting with an initial / or //), start their selection from the root GNode of a GTree; relative path expressions (those without a leading / or //) start from the context value.

4.6.2 Relative Path Expressions

RelativePathExpr::=StepExpr (("/" | "//") StepExpr)*
StepExpr::=PostfixExpr | AxisStep
PostfixExpr::=PrimaryExpr | FilterExpr | DynamicFunctionCall | LookupExpr | FilterExprAM
AxisStep::=(AbbreviatedStep | FullStep) Predicate*

A relative relative path expression is a path expression that selects GNodes within a GTree by following a series of steps starting at the GNodes in the context value (which may be any kind of GNode, not necessarily the root of the tree).

Each non-initial occurrence of // in a path expression is expanded as described in 4.6.7 Abbreviated Syntax, leaving a sequence of steps separated by /. This sequence of steps is then evaluated from left to right. So a path such as E1/E2/E3/E4 is evaluated as ((E1/E2)/E3)/E4. The semantics of a path expression are thus defined by the semantics of the binary / operator, which is defined in 4.6.3 Path operator (/).

Note:

Although the semantics describe the evaluation of a path with more than two steps as proceeding from left to right, the / operator is in most cases associative, so evaluation from right to left usually delivers the same result. The cases where / is not associative arise when the functions fn:position() and fn:last() are used: A/B/position() delivers a sequence of integers from 1 to the size of (A/B), whereas A/(B/position()) restarts the counting at each B element.

The following example illustrates the use of a relative path expressions to select within an XTree. It is assumed that the context value is a single XNode, referred to as the context node.

  • child::div1/child::para

    Selects the para element children of the div1 element children of the context node; that is, the para element grandchildren of the context node that have div1 parents.

Note:

Since each step in a path provides context GNodes for the following step, in effect, only the last step in a path is allowed to return a sequence of non-GNodes.

4.6.4 Axis Steps

AxisStep::=(AbbreviatedStep | FullStep) Predicate*
AbbreviatedStep::=".." | ("@" NodeTest) | SimpleNodeTest
FullStep::=AxisNodeTest
Axis::=("ancestor" | "ancestor-or-self" | "attribute" | "child" | "descendant" | "descendant-or-self" | "following" | "following-or-self" | "following-sibling" | "following-sibling-or-self" | "namespace" | "parent" | "preceding" | "preceding-or-self" | "preceding-sibling" | "preceding-sibling-or-self" | "self") "::"
NodeTest::=UnionNodeTest | SimpleNodeTest
Predicate::="[" Expr "]"
Expr::=(ExprSingle ++ ",")
ExprSingle::=ForExpr| LetExpr| QuantifiedExpr| IfExpr| OrExpr

[Definition: 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.]

Note:

An axis step is an expression in its own right. While axis steps are often used as the operands of path expressions, they can also appear in other contexts (without a / or // operator); equally, the operands of a path expression can be any expression, not restricted to an axis step.

If the context value for an axis step includes a map or array, this is implicitly converted to a JNode as if by applying the fn:jnode function. If, after this conversion, the sequence contains a value that is not a GNode, a type error is raised [err:XPTY0020]. The result of evaluating the axis step is a sequence of zero or more GNodes.

The axis stepS is equivalent to ./S. Thus, if the context value is a sequence containing multiple GNodes, the semantics of a axis step are equivalent to a path expression in which the step is always applied to a single GNode. The following description therefore explains the semantics for the case where the context value is a single GNode, called the origin.

Note:

The equivalence of a axis stepS to the path expression./S means that the resulting GNode sequence is returned in document order.

In the abbreviated syntax for a step, the axis can be omitted and other shorthand notations can be used as described in 4.6.7 Abbreviated Syntax.

The unabbreviated syntax for an axis step consists of the axis name and node test separated by a double colon. The result of the step consists of the GNodes reachable from the origin via the specified axis that match the node test. For example, the step child::para selects the para element children of the origin XNode: child is the name of the axis, and para is the name of the element nodes to be selected on this axis. The available axes are described in 4.6.4.1 Axes. The available node tests are described in 4.6.4.2 Node Tests. Examples of steps are provided in 4.6.6 Unabbreviated Syntax and 4.6.7 Abbreviated Syntax.

4.6.4.2 Node Tests

Changes in 4.0  

  1. 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.   [Issue 296 PR 1181 30 April 2024]

[Definition: 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.]

NodeTest::=UnionNodeTest | SimpleNodeTest
UnionNodeTest::="(" (SimpleNodeTest ++ "|") ")"
SimpleNodeTest::=TypeTest | Selector
TypeTest::=RegularItemType | ("type" "(" SequenceType ")")
Selector::=EQName | Wildcard | ("get" "(" Expr ")")
EQName::=QName | URIQualifiedName
Wildcard::="*"
| (NCName ":*")
| ("*:" NCName)
| (BracedURILiteral "*")
/* ws: explicit */
Expr::=(ExprSingle ++ ",")
ExprSingle::=ForExpr| LetExpr| QuantifiedExpr| IfExpr| OrExpr

Node tests fall into three categories:

  • Type tests, which test the type of the GNode;

  • Selectors, which act as keys used to identify the GNode among its siblings (in the case of XNodes, this is the node name);

  • Union node tests, which provide multiple conditions: a GNode satisfies the union node test if it satisfies any of its operand node tests.

A UnionNodeTest matches a node N if at least one of the constituent SimpleNodeTests matches N.

For example, (div1|div2|div3) matches a node named div1, div2, or div3

The semantics of selectors varies between XNodes and JNodes, so the two cases are described separately.

4.6.5 Predicates within Steps

AxisStep::=(AbbreviatedStep | FullStep) Predicate*
AbbreviatedStep::=".." | ("@" NodeTest) | SimpleNodeTest
FullStep::=AxisNodeTest
Axis::=("ancestor" | "ancestor-or-self" | "attribute" | "child" | "descendant" | "descendant-or-self" | "following" | "following-or-self" | "following-sibling" | "following-sibling-or-self" | "namespace" | "parent" | "preceding" | "preceding-or-self" | "preceding-sibling" | "preceding-sibling-or-self" | "self") "::"
NodeTest::=UnionNodeTest | SimpleNodeTest
Predicate::="[" Expr "]"
Expr::=(ExprSingle ++ ",")
ExprSingle::=ForExpr| LetExpr| QuantifiedExpr| IfExpr| OrExpr

A predicate within an AxisStep has similar syntax and semantics to a predicate within a filter expression. The only difference is in the way the context position is set for evaluation of the predicate.

Note:

The operator [] binds more tightly than /. This means that the expression a/b[1] is interpreted as child::a/(child::b[1]): it selects the first b child of every a element, in contrast to (a/b)[1] which selects the first b element that is a child of some a element.

A common mistake is to write //a[1] where (//a)[1] is intended. The first expression, //a[1], selects every descendant a element that is the first child of its parent (it expands to /descendant-or-self::node()/child::a[1]), whereas (//a)[1] selects the a element in the document.

For the purpose of evaluating the context position within a predicate, the input sequence is considered to be sorted as follows: into document order if the predicate is in a forward-axis step, into reverse document order if the predicate is in a reverse-axis step, or in its original order if the predicate is not in a step.

More formally:

  • For a step using a forwards axis, such as child::test[P], the result is the same as for the equivalent filter expression(child::test)[P] (note the parentheses). The same applies if there are multiple predicates, for example child::test[P1][P2][P3] is equivalent to (child::test)[P1][P2][P3].

  • For a step using a reverse axis, such as ancestor::test[P], the result is the same as the expression reverse(ancestor::test)[P] => reverse(). The same applies if there are multiple predicates, for example ancestor::test[P1][P2][P3] is equivalent to reverse(ancestor::test)[P1][P2][P3] => reverse().

Note:

The result of the expression preceding-sibling::* is in document order, but preceding-sibling::*[1] selects the last preceding sibling element, that is, the one that immediately precedes the context node.

Similarly, the expression preceding-sibling::x[1, 2, 3] selects the last three preceding siblings, returning them in document order. For example, given the input:

<doc><a/><b/><c/><d/><e/><f/></doc>

The result of //e ! preceding-sibling::*[1, 2, 3] is <b/>, <c/>, <d/>. The expression //e ! preceding-sibling::*[3, 2, 1] delivers exactly the same result.

Here are some examples of axis steps that contain predicates to select XNodes:

  • This example selects the second chapter element that is a child of the context node:

    child::chapter[2]
  • This example selects all the descendants of the context node that are elements named "toy" and whose color attribute has the value "red":

    descendant::toy[attribute::color = "red"]
  • This example selects all the employee children of the context node that have both a secretary child element and an assistant child element:

    child::employee[secretary][assistant]
  • This example selects the innermost div ancestor of the context node:

    ancestor::div[1]
  • This example selects the outermost div ancestor of the context node:

    ancestor::div[last()]
  • This example selects the names of all the ancestor elements of the context node that have an @id attribute, outermost element first:

    ancestor::*[@id]

Note:

The expression ancestor::div[1] parses as an AxisStep with a reverse axis, and the position 1 therefore refers to the first ancestor div in reverse document order, that is, the innermost div. By contrast, (ancestor::div)[1] parses as a FilterExpr, and therefore returns the first qualifying div element in the order of the ancestor::div expression, which is in document order.

The fact that a reverse-axis step assigns context positions in reverse document order for the purpose of evaluating predicates does not alter the fact that the final result of the step is always in document order.

The expression ancestor::(div1|div2)[1] does not have the same meaning as (ancestor::div1|ancestor::div2)[1]. In the first expression, the predicate [1] is within a step that uses a reverse axis, so nodes are counted in reverse document order. In the second expression, the predicate applies to the result of a union expression, so nodes are counted in document order.

When the context value for evaluation of a step includes multiple GNodes, the step is evaluated separately for each of those GNodes, and the results are combined, eliminating duplicates and sorting into document order.

Note:

To avoid reordering and elimination of duplicates, replace the step S by .!S.

4.6.7 Abbreviated Syntax

AbbreviatedStep::=".." | ("@" NodeTest) | SimpleNodeTest
NodeTest::=UnionNodeTest | SimpleNodeTest
SimpleNodeTest::=TypeTest | Selector
TypeTest::=RegularItemType | ("type" "(" SequenceType ")")
Selector::=EQName | Wildcard | ("get" "(" Expr ")")
EQName::=QName | URIQualifiedName
Wildcard::="*"
| (NCName ":*")
| ("*:" NCName)
| (BracedURILiteral "*")
/* ws: explicit */
Expr::=(ExprSingle ++ ",")
ExprSingle::=ForExpr| LetExpr| QuantifiedExpr| IfExpr| OrExpr

The abbreviated syntax permits the following abbreviations:

  1. The attribute axis attribute:: can be abbreviated by @. For example, the expression para[@type = "warning"] is short for child::para[attribute::type = "warning"] and so selects para children with a type attribute with value equal to warning.

  2. If the axis name is omitted from an axis step, the default axis is child, with two exceptions: (1) if the NodeTest in an axis step contains an AttributeTest or SchemaAttributeTest then the default axis is attribute; (2) if the NodeTest in an axis step is a NamespaceNodeTestthen the default axis is namespace, but in an implementation that does not support the namespace axis, an error is raised [err:XQST0134].

    Note:

    The namespace axis is deprecated as of XPath 2.0, but is required in some languages that use XPath, including XSLT.

    For example, the path expression section/para is an abbreviation for child::section/child::para, and the path expression section/@id is an abbreviation for child::section/attribute::id. Similarly, section/attribute(id) is an abbreviation for child::section/attribute::attribute(id). Note that the latter expression contains both an axis specification and a node test.

    Similarly, within a JTree rooted at an array, the expression get(1)/parts/get(2)/part-no gets the first member of the top-level array (presumably a map), then the "parts" entry within this map (presumably an array), then the second member of this array (presumably a map), and finally the part-no entry within this map.

    Note:

    The same selection could be made using the lookup expression ?1?parts?2?part-no. The main difference is that path expressions offer more flexibility in being able to navigate around the containing JTree. Also, the lookup expression $a?1 fails if the array index is out of bounds; the path expression $a/get(1) (or $a/*[1]) instead returns an empty sequence.

    Note:

    An abbreviated axis step that omits the axis name must use a SimpleNodeTest rather than a UnionNodeTest. This means that a construct such as (ul|ol) is treated as an abbreviation for (child::ul|child::ol) rather than child::(ul|ol). Since the two constructs have exactly the same semantics, this is not actually a restriction.

  3. A step consisting of .. is short for parent::gnode(). For example (assuming the context item is an XNode), ../title is short for parent::gnode()/child::title and so will select the title children of the parent of the context node.

    Similarly, if $dateOfBirth is a JNode resulting from the expression $map/get("date of birth"), then $dateOfBirth/../gender will select the entry having key "gender" within $map.

    Note:

    The expression ., known as a context value reference, is a primary expression, and is described in 4.2.3 Context Value References.

Here are some examples of path expressions that use the abbreviated syntax. These examples assume that the context value is a single XNode, referred to as the context node:

  • para selects the para element children of the context node.

  • * selects all element children of the context node.

  • text() selects all text node children of the context node.

  • @name selects the name attribute of the context node.

  • @(id|name) selects the id and name attributes of the context node.

  • @* selects all the attributes of the context node.

  • para[1] selects the first para child of the context node.

  • para[last()] selects the last para child of the context node.

  • */para selects all para grandchildren of the context node.

  • /book/chapter[5]/section[2] selects the second section of the fifth chapter of the book whose parent is the document node that contains the context node.

  • chapter//para selects the para element descendants of the chapter element children of the context node.

  • //para selects all the para descendants of the root document node and thus selects all para elements in the same document as the context node.

  • //@version selects all the version attribute nodes that are in the same document as the context node.

  • //list/member selects all the member elements in the same document as the context node that have a list parent.

  • .//para selects the para element descendants of the context node.

  • .. selects the parent of the context node.

  • ../@lang selects the lang attribute of the parent of the context node.

  • para[@type = "warning"] selects all para children of the context node that have a type attribute with value warning.

  • para[@type = "warning"][5] selects the fifth para child of the context node that has a type attribute with value warning.

  • para[5][@type = "warning"] selects the fifth para child of the context node if that child has a type attribute with value warning.

  • chapter[title = "Introduction"] selects the chapter children of the context node that have one or more title children whose typed value is equal to the string Introduction.

  • chapter[title] selects the chapter children of the context node that have one or more title children.

  • employee[@secretary and @assistant] selects all the employee children of the context node that have both a secretary attribute and an assistant attribute.

  • book/(chapter|appendix)/section selects every section element that has a parent that is either a chapter or an appendix element, that in turn is a child of a book element that is a child of the context node.

  • If E is any expression that returns a sequence of nodes, then the expression E/. returns the same nodes in document order, with duplicates eliminated based on node identity.

The following examples use abbreviated paths to access data within the JTree obtained by parsing the JSON text:

[
  { "first": "John", 
    "last": "Baker", 
    "date of birth": "2003-04-19", 
    "occupation": "cook"}, 
  { "first": "Mary", 
    "last": "Smith", 
    "date of birth": "2006-08-12", 
    "occupation": "teacher"},                 
]
  • get(1)/first returns a JNode whose ·content· is the string "John".

  • //first[. = "Mary"]/../last returns a JNode whose ·content· is the string "Smith".

  • //first[. = "Mary"]/../get("date of birth") returns a JNode whose ·content· is the string "2006-08-12".

  • //*[occupation = "cook"]!`{first} {last}` returns the string "John Baker".

  • //*[occupation = "cook"]/following-sibling::*[1]!`{first} {last}` returns the string "Mary Smith".

  • //*[last = "Smith"]/../get(1)/last returns the string "Baker".

  • //record(first, last, *) ! string(last) returns the sequence of two strings "Baker", "Smith".

4.7 Sequence Expressions

XPath 4.0 supports operators to construct, filter, and combine sequences of items. Sequences are never nested—for example, combining the values 1, (2, 3), and ( ) into a single sequence results in the sequence (1, 2, 3).

4.7.1 Sequence Concatenation

RangeExprExprRangeExprExpr::=AdditiveExpr(ExprSingle ("to++ "," AdditiveExpr)?
AdditiveExprExprSingleAdditiveExprExprSingle::=MultiplicativeExpr (("+" ForExpr
| LetExpr
"-")| MultiplicativeExprQuantifiedExpr
)| IfExpr
*| OrExpr

[Definition: 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.]

The result of a sequence expression is the sequence concatenation of the values of its operands. See

[Definition: A comma operator is a comma used specifically as the operator in a sequence expression.]

Empty parentheses can be used to denote an empty sequence.

A sequence may contain duplicate items, but a sequence is never an item in another sequence. When a new sequence is created by concatenating two or more input sequences, the new sequence contains all the items of the input sequences and its length is the sum of the lengths of the input sequences.

[Definition: 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.] The comma operator returns the sequence concatenation of its two operands; repeated application (for example $s1, $s2, $s3, $s4) delivers the sequence concatenation of multiple sequences.

Note:

In places where the grammar calls for ExprSingle, such as the arguments of a function call, any expression that contains a top-level comma operator must be enclosed in parentheses.

Here are some examples of expressions that construct sequences:

  • The result of this expression is a sequence of five integers:

    (10, 1, 2, 3, 4)
  • This expression combines four sequences of length one, two, zero, and two, respectively, into a single sequence of length five. The result of this expression is the sequence 10, 1, 2, 3, 4.

    (10, (1, 2), (), (3, 4))
  • The result of this expression is a sequence containing all salary children of the context node followed by all bonus children.

    (salary, bonus)
  • Assuming that $price is bound to the value 10.50, the result of this expression is the sequence 10.50, 10.50.

    ($price, $price)

4.7.2 Range Expressions

RangeExprRangeExprRangeExprRangeExpr::=AdditiveExpr ("to" AdditiveExpr)?
AdditiveExprAdditiveExprAdditiveExprAdditiveExpr::=MultiplicativeExpr (("+" | "-") MultiplicativeExpr)*

[Definition: A range expression is a non-trivial instance of the production RangeExpr. A range expression is used to construct a sequence of integers.] Each of the operands is converted as though it was an argument of a function with the expected parameter type xs:integer?. If either operand is an empty sequence, or if the integer derived from the first operand is greater than the integer derived from the second operand, the result of the range expression is an empty sequence. If the two operands convert to the same integer, the result of the range expression is that integer. Otherwise, the result is a sequence containing the two integer operands and every integer between the two operands, in increasing order.

The following examples illustrate the semantics:

  • 1 to 4 returns the sequence 1, 2, 3, 4

  • 10 to 10 returns the singleton sequence 10

  • 10 to 1 returns the empty sequence

  • -13 to -10 returns the sequence -13, -12, -11, -10

More formally, a range expression is evaluated as follows:

  1. Each of the operands of the to operator is converted as though it was an argument of a function with the expected parameter type xs:integer?.

  2. If either operand is an empty sequence, or if the integer derived from the first operand is greater than the integer derived from the second operand, the result of the range expression is an empty sequence.

  3. If the two operands convert to the same integer, the result of the range expression is that integer.

  4. Otherwise, the result is a sequence containing the two integer operands and every integer between the two operands, in increasing order.

The following examples illustrate the use of range expressions.

This example uses a range expression as one operand in constructing a sequence. It evaluates to the sequence 10, 1, 2, 3, 4.

(10, 1 to 4)

This example selects the first four items from an input sequence:

$input[1 to 4]

This example returns the sequence (0, 0.1, 0.2, 0.3, 0.5):

$x = (1 to 5) ! . * 0.1

This example constructs a sequence of length one containing the single integer 10.

10 to 10

The result of this example is a sequence of length zero.

15 to 10

This example uses the fn:reverse function to construct a sequence of six integers in decreasing order. It evaluates to the sequence 15, 14, 13, 12, 11, 10.

reverse(10 to 15)

Note:

To construct a sequence of integers based on steps other than 1, use the fn:slice function, as defined in Section 14.1 General functions and operators on sequences FO31.

4.13 Maps and Arrays

Most modern programming languages have support for collections of key/value pairs, which may be called maps, dictionaries, associative arrays, hash tables, keyed lists, or objects (these are not the same thing as objects in object-oriented systems). In XPath 4.0, we call these maps. Most modern programming languages also support ordered lists of values, which may be called arrays, vectors, or sequences. In XPath 4.0, we have both sequences and arrays. Unlike sequences, an array is an item, and can appear as an item in a sequence.

Note:

The XPath 4.0 specification focuses on syntax provided for maps and arrays, especially constructors and lookup.

Some of the functionality typically needed for maps and arrays is provided by functions defined in Section 18 Processing mapsFO and Section 19 Processing arraysFO, including functions used to read JSON to create maps and arrays, serialize maps and arrays to JSON, combine maps to create a new map, remove map entries to create a new map, iterate over the keys of a map, convert an array to create a sequence, combine arrays to form a new array, and iterate over arrays in various ways.

4.13.4 Filter Expressions for Maps and Arrays

Changes in 4.0  

  1. Filter expressions for maps and arrays are introduced.   [Issue 1159 PR 1163 20 April 2024]

  2. Predicates in filter expressions for maps and arrays can now be numeric.   [Issue 1207 PR 1217 15 May 2024]

FilterExprAM::=PostfixExpr "?[" Expr "]"
PostfixExpr::=PrimaryExpr | FilterExpr | DynamicFunctionCall | LookupExpr | FilterExprAM
Expr::=(ExprSingle ++ ",")
ExprSingle::=ForExpr| LetExpr| QuantifiedExpr| IfExpr| OrExpr

Maps and arrays can be filtered using the construct INPUT?[FILTER]. For example, $array?[count(.)=1] filters an array to retain only those members that are single items.

Note:

The character-pair ?[ forms a single token; no intervening whitespace or comment is allowed.

The required type of the left-hand operand INPUT is (map(*)|array(*))?: that is, it must be either an empty sequence, a single map, or a single array [err:XPTY0004]. However, the coercion rules also allow a JNode whose ·content· is a map or array to be supplied. If the value is an empty sequence, the result of the expression is an empty sequence.

If the value of INPUT is an array, then the FILTER expression is evaluated for each member of the array, with that member as the context value, with its position in the array as the context position, and with the size of the array as the context size. The result of the expression is an array containing those members of the input array for which the predicate truth value of the FILTER expression is true. The order of retained members is preserved.

For example, the following expression:

let $array := [ (), 1, (2, 3), (4, 5, 6) ]
return $array?[count(.) ge 2]

returns:

[ (2, 3), (4, 5, 6) ]

Note:

Numeric predicates are handled in the same way as with filter expressions for sequences. However, the result is always an array, even if only one member is selected. For example, given the $array shown above, the result of $array?[3] is the single-member arrayDM[ (2, 3) ]. Contrast this with $array?3 which delivers the sequence 2, 3.

If the value of INPUT is a map, then the FILTER expression is evaluated for each entry in the map, with the context value set to an item of type record(key as xs:anyAtomicType, value as item()*), in which the key and value fields represent the key and value of the map entry. The context position is the position of the entry in the map (in entry orderDM), and the context size is the number of entries in the map. The result of the expression is a map containing those entries of the input map for which the predicate truth value of the FILTER expression is true. The relative order of entries in the result retains the relative order of entries in the input.

For example, the following expression:

let map := { 1: "alpha", 2: "beta", 3: "gamma" }
return $map?[?key ge 2]

returns:

{ 2: "beta", 3: "gamma" }

Note:

A filter expression such as $map?[last()-1, last()] might be used to return the last two entries of a map in entry orderDM.

4.14 Conditional Expressions

Changes in 4.0  

  1. Alternative syntax for conditional expressions is available: if (condition) { X }.   [Issue 234 PR 284 23 January 2023]

XPath 4.0 allows conditional expressions to be written in several different ways.

IfExpr::="if" "(" Expr ")" (UnbracedActions | BracedAction)
Expr::=(ExprSingle ++ ",")
UnbracedActions::="then" ExprSingle "else" ExprSingle
ExprSingle::=ForExpr
| LetExpr
| QuantifiedExpr
| IfExpr
| OrExpr
UnbracedActions::="then" ExprSingle "else" ExprSingle
BracedAction::=EnclosedExpr
EnclosedExpr::="{" Expr? "}"

The braced expression if (C) then {T} is equivalent to the unbraced expression if (C) then T else ().

The value V of a conditional expression in the form if (C) then T else E is obtained as follows:

  1. Let B be the effective boolean value of the test expression C, as defined in 2.5.4 Effective Boolean Value.

  2. If B is true, V is the result of evaluating T.

  3. Otherwise, V is the result of evaluating E.

Conditional expressions have a special rule for propagating dynamic errors: expressions whose value is not needed for computing the result are guarded, as described in 2.4.5 Guarded Expressions, to prevent spurious dynamic errors.

Here are some examples of conditional expressions:

  • In this example, the test expression is a comparison expression:

    if ($widget1/unit-cost < $widget2/unit-cost)
    then $widget1
    else $widget2
  • In this example, the test expression tests for the existence of an attribute named discounted, independently of its value:

    if ($part/@discounted)
    then $part/wholesale
    else $part/retail
  • The following example returns the attribute node @discount provided the value of @price is greater than 100; otherwise it returns the empty sequence:

    if (@price gt 100) { @discount }
  • The following example tests a number of conditions:

    if (@code = 1) then
      "food"
    else if (@code = 2) then
      "fashion"
    else if (@code = 3) then
      "household"
    else 
      "general"

Note:

The “dangling else ambiguity” found in many other languages cannot arise:

  • In the unbraced format, both the then and else clauses are mandatory.

  • In the braced format, the expression terminates unambiguously with the closing brace.

A XPath 4.0 Grammar

A.1 EBNF

Changes in 4.0  

  1. 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.  [Issue 1366 PR 1498]

The grammar of XPath 4.0 uses the same simple Extended Backus-Naur Form (EBNF) notation as [XML 1.0] with the following differences.

  • The notation XYZ ** "," indicates a sequence of zero or more occurrences of XYZ, with a single comma between adjacent occurrences.

  • The notation XYZ ++ "," indicates a sequence of one or more occurrences of XYZ, with a single comma between adjacent occurrences.

  • All named symbols have a name that begins with an uppercase letter.

  • It adds a notation for referring to productions in external specifications.

  • Comments or extra-grammatical constraints on grammar productions are between '/*' and '*/' symbols.

    • A 'xgc:' prefix is an extra-grammatical constraint, the details of which are explained in A.1.2 Extra-grammatical Constraints

    • A 'ws:' prefix explains the whitespace rules for the production, the details of which are explained in A.3.5 Whitespace Rules

    • A 'gn:' prefix means a 'Grammar Note', and is meant as a clarification for parsing rules, and is explained in A.1.3 Grammar Notes. These notes are not normative.

The terminal symbols for this grammar include the quoted strings used in the production rules below, and the terminal symbols defined in section A.3.1 Terminal Symbols. The grammar is a little unusual in that parsing and tokenization are somewhat intertwined: for more details see A.3 Lexical structure.

The EBNF notation is described in more detail in A.1.1 Notation.

AbbreviatedStep::=".." | ("@" NodeTest) | SimpleNodeTest
AbsolutePathExpr::=("/" RelativePathExpr?) | ("//" RelativePathExpr)
AdditiveExpr::=MultiplicativeExpr (("+" | "-") MultiplicativeExpr)*
AndExpr::=ComparisonExpr ("and" ComparisonExpr)*
AnyArrayType::="array" "(" "*" ")"
AnyFunctionType::=("function" | "fn") "(" "*" ")"
AnyItemTest::="item" "(" ")"
AnyMapType::="map" "(" "*" ")"
AnyNodeKindTest::="node" "(" ")"
AnyRecordType::="record" "(" "*" ")"
Argument::=ExprSingle | ArgumentPlaceholder
ArgumentList::="(" ((PositionalArguments ("," KeywordArguments)?) | KeywordArguments)? ")"
ArgumentPlaceholder::="?"
ArrayConstructor::=SquareArrayConstructor | CurlyArrayConstructor
ArrayType::=AnyArrayType | TypedArrayType
ArrowExpr::=UnaryExpr (SequenceArrowTarget | MappingArrowTarget)*
ArrowTarget::=FunctionCall | RestrictedDynamicCall
AttributeName::=EQName
AttributeTest::="attribute" "(" (NameTestUnion ("," TypeName)?)? ")"
Axis::=("ancestor" | "ancestor-or-self" | "attribute" | "child" | "descendant" | "descendant-or-self" | "following" | "following-or-self" | "following-sibling" | "following-sibling-or-self" | "namespace" | "parent" | "preceding" | "preceding-or-self" | "preceding-sibling" | "preceding-sibling-or-self" | "self") "::"
AxisStep::=(AbbreviatedStep | FullStep) Predicate*
BracedAction::=EnclosedExpr
CastableExpr::=CastExpr ("castable" "as" CastTarget "?"?)?
CastExpr::=PipelineExpr ("cast" "as" CastTarget "?"?)?
CastTarget::=TypeName | ChoiceItemType | EnumerationType
ChoiceItemType::="(" (ItemType ++ "|") ")"
CommentTest::="comment" "(" ")"
ComparisonExpr::=OtherwiseExpr ((ValueComp | GeneralComp | NodeComp) OtherwiseExpr)?
ContextValueRef::="."
CurlyArrayConstructor::="array" EnclosedExpr
DocumentTest::="document-node" "(" (ElementTest | SchemaElementTest | NameTestUnion)? ")"
DynamicFunctionCall::=PostfixExprPositionalArgumentList
ElementName::=EQName
ElementTest::="element" "(" (NameTestUnion ("," TypeName "?"?)?)? ")"
EnclosedExpr::="{" Expr? "}"
EnumerationType::="enum" "(" (StringLiteral ++ ",") ")"
EQName::=QName | URIQualifiedName
ExprExpr::=(ExprSingle ++ ",")
ExprSingle::=ForExpr
| LetExpr
| QuantifiedExpr
| IfExpr
| OrExpr
ExtensibleFlag::="," "*"
FieldDeclaration::=FieldName "?"? ("as" SequenceType)?
FieldName::=NCName | StringLiteral
FilterExpr::=PostfixExprPredicate
FilterExprAM::=PostfixExpr "?[" Expr "]"
ForBinding::=ForItemBinding | ForMemberBinding | ForEntryBinding
ForClause::="for" (ForBinding ++ ",")
ForEntryBinding::=((ForEntryKeyBindingForEntryValueBinding?) | ForEntryValueBinding) PositionalVar? "in" ExprSingle
ForEntryKeyBinding::="key" VarNameAndType
ForEntryValueBinding::="value" VarNameAndType
ForExpr::=ForClauseForLetReturn
ForItemBinding::=VarNameAndTypePositionalVar? "in" ExprSingle
ForLetReturn::=ForExpr | LetExpr | ("return" ExprSingle)
ForMemberBinding::="member" VarNameAndTypePositionalVar? "in" ExprSingle
FullStep::=AxisNodeTest
FunctionBody::=EnclosedExpr
FunctionCall::=EQNameArgumentList
/* xgc: reserved-function-names */
/* gn: parens */
FunctionItemExpr::=NamedFunctionRef | InlineFunctionExpr
FunctionSignature::="(" ParamList ")" TypeDeclaration?
FunctionType::=AnyFunctionType
| TypedFunctionType
GeneralComp::="=" | "!=" | "<" | "<=" | ">" | ">="
GNodeType::="gnode" "(" ")"
IfExpr::="if" "(" Expr ")" (UnbracedActions | BracedAction)
InlineFunctionExpr::=MethodAnnotation* ("function" | "fn") FunctionSignature? FunctionBody
InstanceofExpr::=TreatExpr ("instance" "of" SequenceType)?
IntersectExceptExpr::=InstanceofExpr (("intersect" | "except") InstanceofExpr)*
ItemType::=RegularItemType | FunctionType | TypeName | ChoiceItemType
JNodeType::="jnode-type" "(" SequenceType? ")"
KeySpecifier::=NCName | IntegerLiteral | StringLiteral | VarRef | ParenthesizedExpr | LookupWildcard
KeywordArgument::=EQName ":=" Argument
KeywordArguments::=(KeywordArgument ++ ",")
LetArrayBinding::="$" "[" (VarNameAndType ++ ",") "]" TypeDeclaration? ":=" ExprSingle
LetBinding::=LetValueBinding | LetSequenceBinding | LetArrayBinding | LetMapBinding
LetClause::="let" (LetBinding ++ ",")
LetExpr::=LetClauseForLetReturn
LetMapBinding::="$" "{" (VarNameAndType ++ ",") "}" TypeDeclaration? ":=" ExprSingle
LetSequenceBinding::="$" "(" (VarNameAndType ++ ",") ")" TypeDeclaration? ":=" ExprSingle
LetValueBinding::=VarNameAndType ":=" ExprSingle
Literal::=NumericLiteral | StringLiteral | QNameLiteral
Lookup::="?" KeySpecifier
LookupExpr::=PostfixExprLookup
LookupWildcard::="*"
MapConstructor::="map"? "{" (MapConstructorEntry ** ",") "}"
MapConstructorEntry::=ExprSingle (":" ExprSingle)?
MappingArrowTarget::="=!>" ArrowTarget
MapType::=AnyMapType | TypedMapType
MethodAnnotation::="%method"
MultiplicativeExpr::=UnionExpr (("*" | "×" | "div" | "÷" | "idiv" | "mod") UnionExpr)*
NamedFunctionRef::=EQName "#" IntegerLiteral
/* xgc: reserved-function-names */
NamespaceNodeTest::="namespace-node" "(" ")"
NameTest::=EQName | Wildcard
NameTestUnion::=(NameTest ++ "|")
NodeComp::="is" | "<<" | ">>"
NodeKindTest::=DocumentTest
| ElementTest
| AttributeTest
| SchemaElementTest
| SchemaAttributeTest
| PITest
| CommentTest
| TextTest
| NamespaceNodeTest
| AnyNodeKindTest
NodeTest::=UnionNodeTest | SimpleNodeTest
NumericLiteral::=IntegerLiteral | HexIntegerLiteral | BinaryIntegerLiteral | DecimalLiteral | DoubleLiteral
OccurrenceIndicator::="?" | "*" | "+"
/* xgc: occurrence-indicators */
OrExpr::=AndExpr ("or" AndExpr)*
OtherwiseExpr::=StringConcatExpr ("otherwise" StringConcatExpr)*
ParamList::=(VarNameAndType ** ",")
ParenthesizedExpr::="(" Expr? ")"
PathExpr::=AbsolutePathExpr
| RelativePathExpr
/* xgc: leading-lone-slash */
PipelineExpr::=ArrowExpr ("->" ArrowExpr)*
PITest::="processing-instruction" "(" (NCName | StringLiteral)? ")"
PositionalArgumentList::="(" PositionalArguments? ")"
PositionalArguments::=(Argument ++ ",")
PositionalVar::="at" VarName
PostfixExpr::=PrimaryExpr | FilterExpr | DynamicFunctionCall | LookupExpr | FilterExprAM
Predicate::="[" Expr "]"
PrimaryExpr::=Literal
| VarRef
| ParenthesizedExpr
| ContextValueRef
| FunctionCall
| FunctionItemExpr
| MapConstructor
| ArrayConstructor
| StringTemplate
| UnaryLookup
QNameLiteral::="#" EQName
QuantifiedExpr::=("some" | "every") (QuantifierBinding ++ ",") "satisfies" ExprSingle
QuantifierBinding::=VarNameAndType "in" ExprSingle
RangeExpr::=AdditiveExpr ("to" AdditiveExpr)?
RecordType::=AnyRecordType | TypedRecordType
RegularItemType::=AnyItemTest | NodeKindTest | GNodeType | JNodeType | MapType | ArrayType | RecordType | EnumerationType
RelativePathExpr::=StepExpr (("/" | "//") StepExpr)*
RestrictedDynamicCall::=(VarRef | ParenthesizedExpr | FunctionItemExpr | MapConstructor | ArrayConstructor) PositionalArgumentList
SchemaAttributeTest::="schema-attribute" "(" AttributeName ")"
SchemaElementTest::="schema-element" "(" ElementName ")"
Selector::=EQName | Wildcard | ("get" "(" Expr ")")
SequenceArrowTarget::="=>" ArrowTarget
SequenceType::=("empty-sequence" "(" ")")
| (ItemTypeOccurrenceIndicator?)
SimpleMapExpr::=PathExpr ("!" PathExpr)*
SimpleNodeTest::=TypeTest | Selector
SquareArrayConstructor::="[" (ExprSingle ** ",") "]"
StepExpr::=PostfixExpr | AxisStep
StringConcatExpr::=RangeExpr ("||" RangeExpr)*
StringTemplate::="`" (StringTemplateFixedPart | StringTemplateVariablePart)* "`"
/* ws: explicit */
StringTemplateFixedPart::=((Char - ('{' | '}' | '`')) | "{{" | "}}" | "``")*
/* ws: explicit */
StringTemplateVariablePart::=EnclosedExpr
/* ws: explicit */
TextTest::="text" "(" ")"
TreatExpr::=CastableExpr ("treat" "as" SequenceType)?
TypedArrayType::="array" "(" SequenceType ")"
TypeDeclaration::="as" SequenceType
TypedFunctionParam::=("$" EQName "as")? SequenceType
TypedFunctionType::=("function" | "fn") "(" (TypedFunctionParam ** ",") ")" "as" SequenceType
TypedMapType::="map" "(" ItemType "," SequenceType ")"
TypedRecordType::="record" "(" (FieldDeclaration ** ",") ExtensibleFlag? ")"
TypeName::=EQName
TypeTest::=RegularItemType | ("type" "(" SequenceType ")")
UnaryExpr::=("-" | "+")* ValueExpr
UnaryLookup::=Lookup
UnbracedActions::="then" ExprSingle "else" ExprSingle
UnionExpr::=IntersectExceptExpr (("union" | "|") IntersectExceptExpr)*
UnionNodeTest::="(" (SimpleNodeTest ++ "|") ")"
ValueComp::="eq" | "ne" | "lt" | "le" | "gt" | "ge"
ValueExpr::=SimpleMapExpr
VarName::="$" EQName
VarNameAndType::="$" EQNameTypeDeclaration?
VarRef::="$" EQName
Wildcard::="*"
| (NCName ":*")
| ("*:" NCName)
| (BracedURILiteral "*")
/* ws: explicit */
XPath::=Expr

F 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 Section 2.1.4 fn:dataFO.

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.

binding collection

The result of evaluating the binding expression in a for expression is called the binding collection

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 Section 5.3 Comparison of stringsFO.

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.

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.

current dateTime

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.

data model

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 [XQuery and XPath Data Model (XDM) 4.0].

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 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 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 is either a namespace URI, or absentDM. The namespace URI, if present, is used for any unprefixed QName appearing in a position where a function name is expected.

default function namespace rule

When an unprefixed lexical QName is expanded using the default function namespace rule, it uses 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 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: !!=#$%method()**:+,-->...///::*:::=<<<<===!>=>>>=>>??[@[]```{{{|||}}}×÷AposStringLiteralBracedURILiteralQuotStringLiteralStringLiteral

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, #) .

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, as defined in Section 8.3.1 fn:booleanFO.

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 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.

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.

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.

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 Section 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 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-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, ,) .

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.

host language

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

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.5.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 Section 3.2.7.3 Timezones XS1-2 or Section 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"

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).

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).

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.

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

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.

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.

method

A method is a function item that has the annotation %method.

minus-sign

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

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.

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-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: ancestorancestor-or-selfandarrayasatattributecastcastablechildcommentdescendantdescendant-or-selfdivdocument-nodeelementelseempty-sequenceenumeqeveryexceptfnfollowingfollowing-or-selffollowing-siblingfollowing-sibling-or-selfforfunctiongegetgnodegtidivifininstanceintersectisitemjnode-typekeyleletltmapmembermodnamespacenamespace-nodenenodeoforotherwiseparentprecedingpreceding-or-selfpreceding-siblingpreceding-sibling-or-selfprocessing-instructionrecordreturnsatisfiesschema-attributeschema-elementselfsometextthentotreattypeunionvalueBinaryIntegerLiteralDecimalLiteralDoubleLiteralHexIntegerLiteralIntegerLiteralNCNameQNameURIQualifiedName

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.

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.

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.

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 Expressionsexpressions 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.

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.

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

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.

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 Section 14.2.1 fn:atomic-equalFO

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 XPath 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 [XSLT and XQuery Serialization 4.0].

singleton

A sequence containing exactly one item is called a singleton.

singleton enumeration type

An enumeration type with a single enumerated value (such as enum("red")) is an anonymous atomic type derived from xs:string by restriction using an enumeration facet that permits only the value "red". 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 expression, 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 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 value

The string value of a node is a string and can be extracted by applying the Section 2.1.3 fn:stringFO 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 Section 2.2.2.2 Element Substitution Group XS1-1 and Section 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 [XQuery and XPath 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.

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.

type annotation

Each element node and attribute node in an XDM instance has a type annotation (described in Section 4.1 Schema InformationDM). The type annotation of a node is a reference to a schema type.

typed value

The typed value of a node is a sequence of atomic items and can be extracted by applying the Section 2.1.4 fn:dataFO 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.

value

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

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.

warning

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.

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.

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 Section 7.1 XML NodesDM.

XPath 1.0 compatibility mode

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

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 Section 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.