View Old View New View Both View Only Previous Next

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

W3C

XQuery 4.0: An XML Query Language

W3C Editor's Draft 2 February12 March 2026

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

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

See also translations.


Abstract

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

A list of changes made since XQuery 3.1 can be found in K 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.


4 Expressions

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

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

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

Expr::=(ExprSingle ++ ",")
ExprSingle::=FLWORExpr
| QuantifiedExpr
| SwitchExpr
| TypeswitchExpr
| IfExpr
| TryCatchExpr
| OrExpr

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

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

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

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

4.18 Switch Expressions

Changes in 4.0  

  1. Switch expressions now allow a case clause to match multiple atomic items.   [Issue 328 PR 364 7 March 2023]

  2. Switch and typeswitch expressions can now be written with curly brackets, to improve readability.   [Issue 365 PR 587 7 November 2023]

  3. The comparand expression in a switch expression can be omitted, allowing the switch cases to be provided as arbitrary boolean expressions.   [Issue 671 PR 678 12 September 2023]

SwitchExpr::="switch" SwitchComparand? (SwitchCases | BracedSwitchCases)
SwitchComparand::="(" Expr? ")"
SwitchCases::=SwitchCaseClause+ "default" "return" ExprSingle
BracedSwitchCases::="{" SwitchCases "}"
SwitchCaseClause::=("case" SwitchCaseOperand)+ "return" ExprSingle
SwitchCaseOperand::=Expr

The switch expression chooses one of several expressions to evaluate based on the input value.

In a switch expression, the switch keyword is followed by an expression enclosed in parentheses, called the switch comparand. This is the expression whose value is being compared. This expression is optional, and defaults to true(). The remainder of the switch expression consists of one or more case clauses, with one or more case operand expressions each, and a default clause.

The first step in evaluating a switch expression is to apply atomization to the value of the switch comparand. Call the result the switch value. If the switch value is a sequence of length greater than one, a type error is raised [err:XPTY0004]. In the absence of a switch comparand, the switch value is the xs:boolean value true.

The switch value is compared to each SwitchCaseOperand in turn until a match is found or the list is exhausted. The matching is performed as follows:

  1. The SwitchCaseOperand is evaluated.

  2. The resulting value is atomized: call this the case value.

  3. If the case value is an empty sequence, then a match occurs if and only if the switch value is an empty sequence.

  4. Otherwise, the singleton switch value is compared individually with each item in the case value in turn, and a match occurs if and only if these two atomic items compare equal under the rules of the fn:deep-equal function with default options, using the default collation in the static context.

[Definition: The effective case of a switch expression is the first case clause that matches, using the rules given above, or the default clause if no such case clause exists.] The value of the switch expression is the value of the return expression in the effective case.

Switch expressions have rules regarding the propagation of dynamic errors: see 2.4.5 Guarded Expressions. These rules mean that the return clauses of a switch expression must not raise any dynamic errors except in the effective case. Dynamic errors raised in the operand expressions of the switch or the case clauses are propagated; however, an implementation must not raise dynamic errors in the operand expressions of case clauses that occur after the effective case. An implementation is permitted to raise dynamic errors in the operand expressions of case clauses that occur before the effective case, but not required to do so.

The following example shows how a switch expression might be used:

switch ($animal) {
  case "Cow" return "Moo"
  case "Cat" return "Meow"
  case "Duck", "Goose" return "Quack"
  default return "What's that odd noise?"
}

The curly brackets in a switch expression are optional. The above example can equally be written:

switch ($animal) 
  case "Cow" return "Moo"
  case "Cat" return "Meow"
  case "Duck", "Goose" return "Quack"
  default return "What's that odd noise?"

The following example illustrates a switch expression where the comparand is defaulted to true:

switch {
  case ($a le $b) return "lesser"
  case ($a ge $b) return "greater"
  case ($a eq $b) return "equal"
  default return "not comparable"
}
switch () {
  case ($a le $b) return "lesser"
  case ($a ge $b) return "greater"
  case ($a eq $b) return "equal"
  default return "not comparable"
}

Note:

The comparisons are performed using the fn:deep-equal function, after atomization. This means that a case expression such as @married tests fn:data(@married) rather than fn:boolean(@married). If the effective boolean value of the expression is wanted, this can be achieved with an explicit call of fn:boolean.

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

AbbrevForwardStep::=("@" NodeTest) | SimpleNodeTest
AbbrevReverseStep::=".."
AdditiveExpr::=MultiplicativeExpr ( ("+" | "-") MultiplicativeExpr )*
AllowingEmpty::="allowing" "empty"
AndExpr::=ComparisonExpr ( "and" ComparisonExpr )*
AnnotatedDecl::="declare" Annotation* (VarDecl | FunctionDecl | ItemTypeDecl | NamedRecordTypeDecl)
Annotation::="%" EQName ("(" (AnnotationValue ++ ",") ")")?
AnnotationValue::=StringLiteral | ("-"? NumericLiteral) | ("true" "(" ")") | ("false" "(" ")")
AnyArrayType::="array" "(" "*" ")"
AnyFunctionType::=("function" | "fn") "(" "*" ")"
AnyItemTest::="item" "(" ")"
AnyKindTest::="node" "(" ")"
AnyMapType::="map" "(" "*" ")"
AnyRecordType::="record" "(" "*" ")"
AposAttrValueContent::=AposAttrContentChar
| CommonContent
Argument::=ExprSingle | ArgumentPlaceholder
ArgumentList::="(" ((PositionalArguments ("," KeywordArguments)?) | KeywordArguments)? ")"
ArgumentPlaceholder::="?"
ArrayConstructor::=SquareArrayConstructor | CurlyArrayConstructor
ArrayType::=AnyArrayType | TypedArrayType
ArrowDynamicFunction::=VarRef | InlineFunctionExpr | ParenthesizedExpr
ArrowExpr::=UnaryExpr ( (SequenceArrowTarget | MappingArrowTarget | LookupArrowTarget) )*
ArrowStaticFunction::=EQName
ArrowTarget::=(ArrowStaticFunctionArgumentList) | (ArrowDynamicFunctionPositionalArgumentList)
AttributeName::=EQName
AttributeTest::="attribute" "(" (NameTestUnion ("," TypeName)?)? ")"
AxisStep::=(ReverseStep | ForwardStep) Predicate*
BaseURIDecl::="declare" "base-uri" URILiteral
BoundarySpaceDecl::="declare" "boundary-space" ("preserve" | "strip")
BracedActions::=ThenActionElseIfAction* ElseAction?
BracedSwitchCases::="{" SwitchCases "}"
BracedTypeswitchCases::="{" TypeswitchCases "}"
CaseClause::="case" (VarName "as")? SequenceTypeUnion "return" ExprSingle
CastableExpr::=CastExpr ( "castable" "as" CastTarget "?"? )?
CastExpr::=ArrowExpr ( "cast" "as" CastTarget "?"? )?
CastTarget::=TypeName | ChoiceItemType | EnumerationType
CatchClause::="catch" NameTestUnionEnclosedExpr
CDataSection::="<![CDATA[" CDataSectionContents "]]>"
/* ws: explicit */
CDataSectionContents::=(Char* - (Char* ']]>' Char*))
/* ws: explicit */
ChoiceItemType::="(" (ItemType ++ "|") ")"
CommentTest::="comment" "(" ")"
CommonContent::=PredefinedEntityRef | CharRef | "{{" | "}}" | EnclosedExpr
ComparisonExpr::=OtherwiseExpr ( (ValueComp
| GeneralComp
| NodeComp) OtherwiseExpr )?
CompAttrConstructor::="attribute" CompNodeNameEnclosedExpr
CompCommentConstructor::="comment" EnclosedExpr
CompDocConstructor::="document" EnclosedExpr
CompElemConstructor::="element" CompNodeNameEnclosedContentExpr
CompNamespaceConstructor::="namespace" CompNodeNCNameEnclosedExpr
CompNodeName::=StringLiteral | UnreservedName | ("{" Expr "}")
CompNodeNCName::=StringLiteral | UnreservedNCName | ("{" Expr "}")
CompPIConstructor::="processing-instruction" CompNodeNCNameEnclosedExpr
CompTextConstructor::="text" EnclosedExpr
ComputedConstructor::=CompDocConstructor
| CompElemConstructor
| CompAttrConstructor
| CompNamespaceConstructor
| CompTextConstructor
| CompCommentConstructor
| CompPIConstructor
ConstructionDecl::="declare" "construction" ("strip" | "preserve")
ContextValueDecl::="declare" "context" (("value" ("as" SequenceType)?) | ("item" ("as" ItemType)?)) ((":=" VarValue) | ("external" (":=" VarDefaultValue)?))
ContextValueRef::="."
CopyNamespacesDecl::="declare" "copy-namespaces" PreserveMode "," InheritMode
CountClause::="count" VarName
CurlyArrayConstructor::="array" EnclosedExpr
CurrentVar::=VarName
DecimalFormatDecl::="declare" (("decimal-format" EQName) | ("default" "decimal-format")) (DFPropertyName "=" StringLiteral)*
DefaultCollationDecl::="declare" "default" "collation" URILiteral
DefaultNamespaceDecl::="declare" "fixed"? "default" ("element" | "function") "namespace" URILiteral
DFPropertyName::="decimal-separator" | "grouping-separator" | "infinity" | "minus-sign" | "NaN" | "percent" | "per-mille" | "zero-digit" | "digit" | "pattern-separator" | "exponent-separator"
DirAttributeList::=(S (QNameS? "=" S? DirAttributeValue)?)*
/* ws: explicit */
DirAttributeValue::=('"' (EscapeQuot | QuotAttrValueContent)* '"')
| ("'" (EscapeApos | AposAttrValueContent)* "'")
/* ws: explicit */
DirCommentConstructor::="<!--" DirCommentContents "-->"
/* ws: explicit */
DirCommentContents::=((Char - '-') | ('-' (Char - '-')))*
/* ws: explicit */
DirectConstructor::=DirElemConstructor
| DirCommentConstructor
| DirPIConstructor
DirElemConstructor::="<" QNameDirAttributeList ("/>" | (">" DirElemContent* "</" QNameS? ">"))
/* ws: explicit */
DirElemContent::=DirectConstructor
| CDataSection
| CommonContent
| ElementContentChar
DirPIConstructor::="<?" PITarget (SDirPIContents)? "?>"
/* ws: explicit */
DirPIContents::=(Char* - (Char* '?>' Char*))
/* ws: explicit */
DocumentTest::="document-node" "(" (ElementTest | SchemaElementTest | NameTestUnion)? ")"
DynamicFunctionCall::=PostfixExprPositionalArgumentList
ElementName::=EQName
ElementTest::="element" "(" (NameTestUnion ("," TypeName "?"?)?)? ")"
ElseAction::="else" EnclosedExpr
ElseIfAction::="else" "if" "(" Expr ")" EnclosedExpr
EmptyOrderDecl::="declare" "default" "order" "empty" ("greatest" | "least")
EnclosedContentExpr::=EnclosedExpr
EnclosedExpr::="{" Expr? "}"
EnumerationType::="enum" "(" (StringLiteral ++ ",") ")"
EQName::=QName | URIQualifiedName
Expr::=(ExprSingle ++ ",")
ExprSingle::=FLWORExpr
| QuantifiedExpr
| SwitchExpr
| TypeswitchExpr
| IfExpr
| TryCatchExpr
| OrExpr
ExtendedFieldDeclaration::=FieldDeclaration (":=" ExprSingle)?
ExtensibleFlag::="," "*"
ExtensionExpr::=Pragma+ "{" Expr? "}"
FieldDeclaration::=FieldName "?"? ("as" SequenceType)?
FieldName::=NCName | StringLiteral
FilterExpr::=PostfixExprPredicate
FilterExprAM::=PostfixExpr "?[" Expr "]"
FLWORExpr::=InitialClauseIntermediateClause* ReturnClause
ForBinding::=ForItemBinding | ForMemberBinding | ForEntryBinding
ForClause::="for" (ForBinding ++ ",")
ForEntryBinding::=((ForEntryKeyBindingForEntryValueBinding?) | ForEntryValueBinding) PositionalVar? "in" ExprSingle
ForEntryKeyBinding::="key" VarNameAndType
ForEntryValueBinding::="value" VarNameAndType
ForItemBinding::=VarNameAndTypeAllowingEmpty? PositionalVar? "in" ExprSingle
ForMemberBinding::="member" VarNameAndTypePositionalVar? "in" ExprSingle
ForwardAxis::=("attribute"
| "child"
| "descendant"
| "descendant-or-self"
| "following"
| "following-or-self"
| "following-sibling"
| "following-sibling-or-self"
| "self") "::"
ForwardStep::=(ForwardAxisNodeTest) | AbbrevForwardStep
FunctionBody::=EnclosedExpr
FunctionCall::=EQNameArgumentList
/* xgc: reserved-function-names */
/* gn: parens */
FunctionDecl::="function" EQName "(" ParamListWithDefaults? ")" TypeDeclaration? (FunctionBody | "external")
/* xgc: reserved-function-names */
FunctionItemExpr::=NamedFunctionRef | InlineFunctionExpr
FunctionSignature::="(" ParamList ")" TypeDeclaration?
FunctionType::=Annotation* (AnyFunctionType
| TypedFunctionType)
GeneralComp::="=" | "!=" | "<" | "<=" | ">" | ">="
GroupByClause::="group" "by" (GroupingSpec ++ ",")
GroupingSpec::=VarName (TypeDeclaration? ":=" ExprSingle)? ("collation" URILiteral)?
IfExpr::="if" "(" Expr ")" (UnbracedActions | BracedActions)
Import::=SchemaImport | ModuleImport
InheritMode::="inherit" | "no-inherit"
InitialClause::=ForClause | LetClause | WindowClause
InlineFunctionExpr::=Annotation* ("function" | "fn") FunctionSignature? FunctionBody
InstanceofExpr::=TreatExpr ( "instance" "of" SequenceType )?
IntermediateClause::=InitialClause | WhereClause | WhileClause | GroupByClause | OrderByClause | CountClause
IntersectExceptExpr::=InstanceofExpr ( ("intersect" | "except") InstanceofExpr )*
ItemType::=AnyItemTest | TypeName | KindTest | FunctionType | MapType | ArrayType | RecordType | EnumerationType | ChoiceItemType
ItemTypeDecl::="type" EQName "as" ItemType
KeySpecifier::=NCName | IntegerLiteral | StringLiteral | VarRef | ParenthesizedExpr | LookupWildcard
KeywordArgument::=EQName ":=" Argument
KeywordArguments::=(KeywordArgument ++ ",")
KindTest::=DocumentTest
| ElementTest
| AttributeTest
| SchemaElementTest
| SchemaAttributeTest
| PITest
| CommentTest
| TextTest
| NamespaceNodeTest
| AnyKindTest
LetBinding::=VarNameAndType ":=" ExprSingle
LetClause::="let" (LetBinding ++ ",")
LibraryModule::=ModuleDeclProlog
Literal::=NumericLiteral | StringLiteral
Lookup::=("?" | "??") (Modifier "::")? KeySpecifier
LookupArrowTarget::="=?>" NCNamePositionalArgumentList
LookupExpr::=PostfixExprLookup
LookupWildcard::="*"
MainModule::=PrologQueryBody
MapConstructor::="map"? "{" (MapConstructorEntry ** ",") "}"
MapConstructorEntry::=MapKeyExpr ":" MapValueExpr
MapKeyExpr::=ExprSingle
MappingArrowTarget::="=!>" ArrowTarget
MapType::=AnyMapType | TypedMapType
MapValueExpr::=ExprSingle
Modifier::="pairs" | "keys" | "values" | "items"
Module::=VersionDecl? (LibraryModule | MainModule)
ModuleDecl::="module" "namespace" NCName "=" URILiteralSeparator
ModuleImport::="import" "module" ("namespace" NCName "=")? URILiteral ("at" (URILiteral ++ ","))?
MultiplicativeExpr::=UnionExpr ( ("*" | "×" | "div" | "÷" | "idiv" | "mod") UnionExpr )*
NamedFunctionRef::=EQName "#" IntegerLiteral
/* xgc: reserved-function-names */
NamedRecordTypeDecl::="record" EQName "(" (ExtendedFieldDeclaration ** ",") ExtensibleFlag? ")"
NamespaceDecl::="declare" "namespace" NCName "=" URILiteral
NamespaceNodeTest::="namespace-node" "(" ")"
NameTest::=EQName | Wildcard
NameTestUnion::=(NameTest ++ "|")
NextVar::="next" VarName
NodeComp::="is" | "<<" | ">>"
NodeConstructor::=DirectConstructor
| ComputedConstructor
NodeTest::=UnionNodeTest | SimpleNodeTest
NumericLiteral::=IntegerLiteral | HexIntegerLiteral | BinaryIntegerLiteral | DecimalLiteral | DoubleLiteral
OccurrenceIndicator::="?" | "*" | "+"
/* xgc: occurrence-indicators */
OptionDecl::="declare" "option" EQNameStringLiteral
OrderByClause::="stable"? "order" "by" OrderSpec ("," OrderSpec)*
OrderedExpr::="ordered" EnclosedExpr
OrderingModeDecl::="declare" "ordering" ("ordered" | "unordered")
OrderModifier::=("ascending" | "descending")? ("empty" ("greatest" | "least"))? ("collation" URILiteral)?
OrderSpec::=ExprSingleOrderModifier
OrExpr::=AndExpr ( "or" AndExpr )*
OtherwiseExpr::=StringConcatExpr ( "otherwise" StringConcatExpr )*
ParamList::=(VarNameAndType ** ",")
ParamListWithDefaults::=(ParamWithDefault ++ ",")
ParamWithDefault::=VarNameAndType (":=" ExprSingle)?
ParenthesizedExpr::="(" Expr? ")"
PathExpr::=("/" RelativePathExpr?)
| ("//" RelativePathExpr)
| RelativePathExpr
/* xgc: leading-lone-slash */
PITest::="processing-instruction" "(" (NCName | StringLiteral)? ")"
PositionalArgumentList::="(" PositionalArguments? ")"
PositionalArguments::=(Argument ++ ",")
PositionalVar::="at" VarName
PostfixExpr::=PrimaryExpr | FilterExpr | DynamicFunctionCall | LookupExpr | FilterExprAM
Pragma::="(#" S? EQName (SPragmaContents)? "#)"
/* ws: explicit */
PragmaContents::=(Char* - (Char* '#)' Char*))
Predicate::="[" Expr "]"
PreserveMode::="preserve" | "no-preserve"
PreviousVar::="previous" VarName
PrimaryExpr::=Literal
| VarRef
| ParenthesizedExpr
| ContextValueRef
| FunctionCall
| OrderedExpr
| UnorderedExpr
| NodeConstructor
| FunctionItemExpr
| MapConstructor
| ArrayConstructor
| StringTemplate
| StringConstructor
| UnaryLookup
Prolog::=((DefaultNamespaceDecl | Setter | NamespaceDecl | Import) Separator)* ((ContextValueDecl | AnnotatedDecl | OptionDecl) Separator)*
QuantifiedExpr::=("some" | "every") QuantifierBinding ("," QuantifierBinding)* "satisfies" ExprSingle
QuantifierBinding::=VarNameAndType "in" ExprSingle
QueryBody::=Expr
QuotAttrValueContent::=QuotAttrContentChar
| CommonContent
RangeExpr::=AdditiveExpr ( "to" AdditiveExpr )?
RecordType::=AnyRecordType | TypedRecordType
RelativePathExpr::=StepExpr (("/" | "//") StepExpr)*
ReturnClause::="return" ExprSingle
ReverseAxis::=("ancestor"
| "ancestor-or-self"
| "parent"
| "preceding"
| "preceding-or-self"
| "preceding-sibling-or-self") "::"
ReverseStep::=(ReverseAxisNodeTest) | AbbrevReverseStep
SchemaAttributeTest::="schema-attribute" "(" AttributeName ")"
SchemaElementTest::="schema-element" "(" ElementName ")"
SchemaImport::="import" "schema" SchemaPrefix? URILiteral ("at" (URILiteral ++ ","))?
SchemaPrefix::=("namespace" NCName "=") | ("fixed"? "default" "element" "namespace")
Separator::=";"
SequenceArrowTarget::="=>" ArrowTarget
SequenceType::=("empty-sequence" "(" ")")
| (ItemTypeOccurrenceIndicator?)
SequenceTypeUnion::=SequenceType ("|" SequenceType)*
Setter::=BoundarySpaceDecl | DefaultCollationDecl | BaseURIDecl | ConstructionDecl | OrderingModeDecl | EmptyOrderDecl | CopyNamespacesDecl | DecimalFormatDecl
SimpleMapExpr::=PathExpr ("!" PathExpr)*
SimpleNodeTest::=KindTest | NameTest
SlidingWindowClause::="sliding" "window" VarNameAndType "in" ExprSingleWindowStartCondition? WindowEndCondition
SquareArrayConstructor::="[" (ExprSingle ** ",") "]"
StepExpr::=PostfixExpr | AxisStep
StringConcatExpr::=RangeExpr ( "||" RangeExpr )*
StringConstructor::="``[" StringConstructorContent "]``"
/* ws: explicit */
StringConstructorChars::=(Char* - (Char* ('`{' | ']``') Char*))
/* ws: explicit */
StringConstructorContent::=StringConstructorChars (StringInterpolationStringConstructorChars)*
/* ws: explicit */
StringInterpolation::="`{" Expr? "}`"
/* ws: explicit */
StringTemplate::="`" (StringTemplateFixedPart | StringTemplateVariablePart)* "`"
/* ws: explicit */
StringTemplateFixedPart::=((Char - ('{' | '}' | '`')) | "{{" | "}}" | "``")*
/* ws: explicit */
StringTemplateVariablePart::=EnclosedExpr
/* ws: explicit */
SwitchCaseClause::=("case" SwitchCaseOperand)+ "return" ExprSingle
SwitchCaseOperand::=Expr
SwitchCases::=SwitchCaseClause+ "default" "return" ExprSingle
SwitchComparand::="(" Expr? ")"
SwitchExpr::="switch" SwitchComparand? (SwitchCases | BracedSwitchCases)
TextTest::="text" "(" ")"
ThenAction::=EnclosedExpr
TreatExpr::=CastableExpr ( "treat" "as" SequenceType )?
TryCatchExpr::=TryClauseCatchClause+
TryClause::="try" EnclosedExpr
TumblingWindowClause::="tumbling" "window" VarNameAndType "in" ExprSingleWindowStartCondition? WindowEndCondition?
TypedArrayType::="array" "(" SequenceType ")"
TypeDeclaration::="as" SequenceType
TypedFunctionType::=("function" | "fn") "(" (SequenceType ** ",") ")" "as" SequenceType
TypedMapType::="map" "(" ItemType "," SequenceType ")"
TypedRecordType::="record" "(" (FieldDeclaration ** ",") ExtensibleFlag? ")"
TypeName::=EQName
TypeswitchCases::=CaseClause+ "default" VarName? "return" ExprSingle
TypeswitchExpr::="typeswitch" "(" Expr ")" (TypeswitchCases | BracedTypeswitchCases)
UnaryExpr::=("-" | "+")* ValueExpr
UnaryLookup::=("?" | "??") (Modifier "::")? KeySpecifier
UnbracedActions::="then" ExprSingle "else" ExprSingle
UnionExpr::=IntersectExceptExpr ( ("union" | "|") IntersectExceptExpr )*
UnionNodeTest::="(" SimpleNodeTest ("|" SimpleNodeTest)* ")"
UnorderedExpr::="unordered" EnclosedExpr
UnreservedName::=EQName
/* xgc: unreserved-name */
UnreservedNCName::=NCName
/* xgc: unreserved-name */
URILiteral::=StringLiteral
ValidateExpr::="validate" (ValidationMode | ("type" TypeName))? "{" Expr "}"
ValidationMode::="lax" | "strict"
ValueComp::="eq" | "ne" | "lt" | "le" | "gt" | "ge"
ValueExpr::=ValidateExpr | ExtensionExpr | SimpleMapExpr
VarDecl::="variable" VarNameAndType ((":=" VarValue) | ("external" (":=" VarDefaultValue)?))
VarDefaultValue::=ExprSingle
VarName::="$" EQName
VarNameAndType::="$" EQNameTypeDeclaration?
VarRef::="$" EQName
VarValue::=ExprSingle
VersionDecl::="xquery" (("encoding" StringLiteral) | ("version" StringLiteral ("encoding" StringLiteral)?)) Separator
WhereClause::="where" ExprSingle
WhileClause::="while" ExprSingle
Wildcard::="*"
| (NCName ":*")
| ("*:" NCName)
| (BracedURILiteral "*")
/* ws: explicit */
WindowClause::="for" (TumblingWindowClause | SlidingWindowClause)
WindowEndCondition::="only"? "end" WindowVars ("when" ExprSingle)?
WindowStartCondition::="start" WindowVars ("when" ExprSingle)?
WindowVars::=CurrentVar? PositionalVar? PreviousVar? NextVar?