XQuery 1.0:XML查询语言 工作草案-7
TransWiki - W3CHINA.ORG开放翻译计划(OTP)
摘要_文档状态_目录 第1节 第2节 3.1~3.3节 3.4~3.6节 3.7节 3.8~3.13节 第4节 附录A 附录B,C,D 附录E,F,G,H,I
| 目录 |
E Glossary
atomic value
An atomic value is a value in the value space of an atomic type, including all the atomic types defined in [XML Schema (http://www.w3.org/TR/2004/WD-xquery-20040723/#XMLSchema)] and xdt:untypedAtomic (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-untypedAtomic).
atomization
Atomization is applied to a value when the value is used in a context in which a sequence of atomic values is required. The result of atomization is either a sequence of atomic values or a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error). Atomization of a sequence is defined as the result of invoking the fn:data function on the sequence, as defined in [XQuery 1.0 and XPath 2.0 Functions and Operators (http://www.w3.org/TR/2004/WD-xquery-20040723/#FunctionsAndOperators)].
available collections
Available collections. This is a mapping of strings onto sequences of nodes. The string represents the absolute URI of a resource. The sequence of nodes represents the result of the fn:collection function when that URI is supplied as the argument.
available documents
Available documents. This is a mapping of strings onto document nodes. The 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 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel). The document node is returned by the fn:doc function when applied to that URI.
base URI
Base URI. This is an absolute URI, used when necessary in the resolution of relative URIs (for example, by the fn:resolve-uri function.)
boundary whitespace
Whitespace characters that occur by themselves in the boundaries between tags and/or enclosed expressions are called boundary whitespace.
computed element constructor
A computed element constructor creates an element node, allowing both the name and the content of the node to be computed.
construction mode
Construction mode. The construction mode governs the behavior of element constructors. If construction mode is preserve, the type of a constructed element node is xs:anyType, and the attributes and descendants of the constructed element retain their original types. If construction mode is strip, the type of the constructed element node and all its descendants is xdt:untyped, and attributes of the constructed element have type xdt:untypedAtomic.
context item
The context item is the item currently being processed. An item is either an atomic value or a node.
context node
When the context item is a node, it can also be referred to as the context node.
context position
The context position is the position of the context item within the sequence of items currently being processed.
context size
The context size is the number of items in the sequence of items currently being processed.
current date and time
Current date and time. This information represents an implementation-dependent (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent) point in time during processing of a query or transformation. It can be retrieved by the fn:current-date, fn:current-time, and fn:current-dateTime functions. If invoked multiple times during the execution of a query or transformation, these functions always return the same result.
data model
XQuery operates on the abstract, logical structure of an XML document, rather than its surface syntax. This logical structure is known as the data model, which is defined in the [XQuery 1.0 and XPath 2.0 Data Model (http://www.w3.org/TR/2004/WD-xquery-20040723/#datamodel)] document.
data model schema
For a given node in the data model (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel), the data model schema is defined as the schema from which the type annotation of that node was derived.
default collation
Default collation. This identifies one of the collations in statically known collations (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-collations) as the collation to be used by string comparison functions and operators when no explicit collation is specified.
default element/type namespace
Default element/type namespace. This is a namespace URI or "none". The namespace URI, if present, is used for any unprefixed QName appearing in a position where an element or type name is expected.
default function namespace
Default function namespace. This is a namespace URI that is used for any unprefixed QName appearing as the function name in a function call. The initial default function namespace may be provided by the external environmentor by a declaration in a Prolog (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-prolog).
default ordering declaration
A default ordering declaration sets the ordering mode (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-ordering-mode) in the static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context).
Delimiting Terminal
A delimiting terminal may delimit adjacent non-delimiting terminals (http://www.w3.org/TR/2004/WD-xquery-20040723/#non-delimiting-token). Delimiting terminals are only recognized in the appropriate lexical states (http://www.w3.org/TR/2004/WD-xquery-20040723/#lexical-state) as specificed by A.2.4 Lexical Rules.
direct element constructor
A direct element constructor is a form of element constructor in which the name of the constructed element is a constant.
document order
Informally, document order is the order defined by a pre-order, depth-first traversal of the nodes in the data model.
dynamic context
The dynamic context of an expression is defined as information that is available at the time the expression is evaluated.
dynamic error
A dynamic error is an error that must be detected during the evaluation phase and may be detected during the analysis phase. Numeric overflow is an example of a dynamic error.
dynamic evaluation phase
The dynamic evaluation phase occurs after completion of the static analysis phase (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis). During the dynamic evaluation phase, the value of the query is computed.
dynamic type
A dynamic type is associated with each value as it is computed. The dynamic type of a value may be either a structural description (such as "sequence of integers") or a named type.
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 [XQuery 1.0 and XPath 2.0 Functions and Operators (http://www.w3.org/TR/2004/WD-xquery-20040723/#FunctionsAndOperators)].
empty sequence
A sequence containing zero items is called an empty sequence.
error value
A dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) carries an error value, which may be a single item or an empty sequence.
expanded QName
An expanded QName consists of an optional namespace URI and a local name.
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 are functions that are implemented outside the query environment.
focus
The first three components of the dynamic context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-context) (context item, context position, and context size) are called the focus of the expression.
Full Axis Feature
An XQuery implementation that supports the Full Axis Feature must support all the optional axes (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-optional-axis).
functional langauge
XQuery is a functional language, which means that expressions can be nested with full generality. (However, unlike a pure functional language, it does not allow variable substitutability if the variable declaration contains construction of new nodes.)
function implementation
Function implementations. Each function in function signatures (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-function-signature) has a function implementation that enables the function to map instances of its parameter types into an instance of its result type. For a user-defined function (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-udf), the function implementation is an XQuery expression. For an external function (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-external-function), the function implementation is implementation-dependent (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent).
function signature
Function signatures. This component defines the set of functions that are available to be called from within an expression. Each function is uniquely identified by its expanded QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-expanded-qname) and its arity (number of parameters).
Ignorable whitespace
Unless otherwise specified (see A.2.2.2 ExplicitSpecial Whitespace Handling), Ignorable whitespace may occur between terminals (http://www.w3.org/TR/2004/WD-xquery-20040723/#terminal), and is not significant to the parse tree. For readability, whitespace may be used in most expressions even though not explicitly notated in the EBNF. All allowable whitespace that is not explicitly specified in the EBNF is ignorable whitespace, and converse, this term does not apply to whitespace that is explicitly specified.
implementation defined
Implementation-defined indicates an aspect that may differ between implementations, but must be specified by the implementor 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 implementor 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 in any other operation. This value is an instance of xdt:dayTimeDuration that is implementation-defined (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-defined) . See [ISO 8601 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ISO8601)] for the range of legal values of a timezone.
initializing expression
If a variable declaration includes an expression, the expression is called an initializing expression.
in-scope attribute declarations
In-scope attribute declarations. Each attribute declaration is identified either by an expanded QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-expanded-qname) (for a top-level attribute declaration) or by an implementation-dependent (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent) attribute identifier (for a local attribute declaration). If the Schema Import Feature (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-schema-import-feature) is supported, in-scope attribute declarations include all attribute declarations found in imported schemas.
in-scope element declarations
In-scope element declarations. Each element declaration is identified either by an expanded QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-expanded-qname) (for a top-level element declaration) or by an implementation-dependent (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent) element identifier (for a local element declaration). If the Schema Import Feature (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-schema-import-feature) is supported, in-scope element declarations include all element declarations found in imported schemas.
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, thus defining the set of namespace prefixes that are available for interpreting QNames within the scope of the element. For a given element, one namespace binding may have an empty prefix; the URI of this namespace binding is the default namespace within the scope of the element.
in-scope schema definitions
In-scope schema definitions. This is a generic term for all the element, attribute, and type definitions that are in scope during processing of an expression.
in-scope type definitions
In-scope type definitions. Each named type definition is identified either by an expanded QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-expanded-qname) (for a named type) or by an implementation-dependent (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent) type identifier (for an anonymous type). The in-scope type definitions include the predefined types described in 2.4.1 Predefined Types. If the Schema Import Feature (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-schema-import-feature) is supported, in-scope type definitions also include all type definitions found in imported schemas.
in-scope variables
In-scope variables. This is a set of (expanded QName, type) pairs. It defines the set of variables that are available for reference within an expression. The expanded QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-expanded-qname) is the name of the variable, and the type is the static type (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type) of the variable.
item
An item is either an atomic value (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-atomic-value) or a node (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-node).
kind test
An alternative form of a node test called a kind test can select nodes based on their kind, name, and type annotation.
lexical action
A lexical action is an action that occurs as an side-effect of a pattern recognition.
lexical state
A lexical state is a condition where a defined set of patterns are recognized.
library module
A module that does not contain a Query Body (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-queryBody) is called a library module.
literal
A literal is a direct syntactic representation of an atomic value.
local namespace declaration
A local namespace declaration in a computed element constructor contains an optional namespace prefix and a namespace URI expressed as a string literal.
main module
A main module consists of single module resource containing a Prolog (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-prolog) followed by a Query Body (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-queryBody).
module
A query can be assembled from one or more fragments called modules. Each module is either a main module (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-main-module) or a library module (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-library-module).
module declaration
A module declaration serves to identify a module resource (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-module-resource) as part of a library module (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-library-module). A module declaration consists of the keyword module followed by a namespace prefix and a string literal which must contain a valid URI. [err:XQ0046 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXQ0046)]
module import
A module import imports the function declarations and variable declarations from a library module (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-library-module) into the function signatures (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-function-signature) and in-scope variables (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-in-scope-variables) of the importing module resource (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-module-resource).
module resource
Each module resource is a fragment of XQuery code that conforms to the Module (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-Module) grammar and can independently undergo the static analysis phase (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis) described in 2.2.3 Expression Processing.
must understand
An implementation may extend XQuery functionality by supporting must-understand extensions. A must-understand extension may be used anywhere that ignorable whitespace (http://www.w3.org/TR/2004/WD-xquery-20040723/#IgnorableWhitespace) is allowed.
namespace declaration
A namespace declaration declares a namespace prefix and associates it with a namespace URI, adding the (prefix, URI) pair to the set of statically known namespaces (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-namespaces).
namespace declaration attribute
A namespace declaration attribute is used inside a direct element constructor. Its purpose is to bind a namespace prefix or to set the default element/type namespace (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-def-elemtype-ns) for the constructed element node, including its attributes.
name test
A node test that consists only of a QName or a Wildcard is called a name test.
node
A node is an instance of one of the node kinds defined in [XQuery 1.0 and XPath 2.0 Data Model (http://www.w3.org/TR/2004/WD-xquery-20040723/#datamodel)].
node test
A node test is a condition that must be true for each node selected by a step.
Non-delimiting Terminal
Non-delimiting terminals generally start and end with alphabetic characters or digits. Adjacent non-delimiting terminals must be delimited by a delimiting terminal (http://www.w3.org/TR/2004/WD-xquery-20040723/#delimiting-token). Non-delimiting terminals are only recognized in the appropriate lexical states (http://www.w3.org/TR/2004/WD-xquery-20040723/#lexical-state) as specificed by A.2.4 Lexical Rules.
optional axis
The following axes are designated as optional axes: ancestor, ancestor-or-self, following, following-sibling, preceding, and preceding-sibling.
ordering mode
Ordering mode. Ordering mode, which has the value ordered or unordered, affects the ordering of the result sequence returned by path expressions, union, intersect, and except expressions, and FLWOR expressions that have no order by clause.
pragma
A pragma may be used to provide additional information to an XQuery implementation.
primary expression
Primary expressions are the basic primitives of the language. They include literals, variable references, context item expressions, constructors, and function calls. A primary expression may also be created by enclosing any expression in parentheses, which is sometimes helpful in controlling the precedence of operators.
principal node kind
Every axis has a principal node kind. If an axis can contain elements, then the principal node kind is element; otherwise, it is the kind of nodes that the axis can contain.
production
A production combines symbols to form more complex patterns.
Prolog
A Prolog is a series of declarations and imports that define the processing environment for the module resource (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-module-resource) that contains the Prolog.
QName
Lexically, a QName consists of an optional namespace prefix and a local name.
query body
The Query Body, if present, consists of an expression that defines the result of the query.
reverse document order
The node ordering that is the reverse of document order is called reverse document order.
schema import
A schema import imports the element, attribute, and type definitions from a schema into the in-scope schema definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd).
Schema Import Feature
If the Schema Import Feature is supported, a Prolog (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-prolog) may contain a schema import (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-schema-import). Definitions from the imported schema are added to the in-scope schema definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd).
sequence
A sequence is an ordered collection of zero or more items (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-item).
SequenceType
When it is necessary to refer to a type in an XQuery expression, the SequenceType (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SequenceType) syntax is used. The name SequenceType (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SequenceType) suggests that this syntax is used to describe the type of an XQuery value, which is always a sequence.
SequenceType matching
During evaluation of an expression, it is sometimes necessary to determine whether a value with a known type "matches" an expected type, expressed in the SequenceType (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SequenceType) syntax. This process is known as SequenceType matching.
serialization
Serialization is the process of converting a sequence of nodes and atomic values from the data model (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel) into a sequence of octets (step DM4 in Figure 1.)
setter
Certain declarations in a Prolog are called setters because they set the value of some property that influences query processing, such as construction mode, ordering mode, or default collation.
singleton sequence
A sequence containing exactly one item is called a singleton sequence.
statically known collations
Statically known collations. This is a set of (URI, collation) pairs. It defines the names of the collations that are available for use in function calls that take a collation name as an argument.
statically known collections
Statically known collections. This is a mapping from strings onto types. The string represents the absolute URI of a resource that is potentially available using the fn:collection function. The type is the type of the sequence of nodes that would result from calling the fn:collection function with this URI as its argument.
statically known documents
Statically known documents. This is a mapping from strings onto types. The string represents the absolute URI of a resource that is potentially available using the fn:doc function. The type is the static type of a call to fn:doc with the given URI as its literal argument.
statically known namespaces
Statically known namespaces. This is a set of (prefix, URI) pairs that define 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 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context). The static analysis phase does not depend on input data (other than schemas).
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
A static error is an error that must be detected during the analysis phase. A syntax error is an example of a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error). The means by which static errors (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) are reported during the analysis phase is implementation-defined (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-defined).
static type
The static type of an expression may be either a named type or a structural description—for example, xs:boolean? denotes an optional occurrence of the xs:boolean type. The rules for inferring the static types (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type) of various expressions are described in [XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)].
static typing extension
A static typing extension is a type inference rule that infers a more precise static type than that inferred by the type inference rules in [XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)].
Static Typing Feature
An XQuery implementation that does not support the Static Typing Feature is not required to raise type errors (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) during the static analysis phase (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis).
strongly typed
XQuery is also a strongly-typed language in which the operands of various expressions, operators, and functions must conform to the expected types.
substitution group
Substitution groups are defined in [XML Schema (http://www.w3.org/TR/2004/WD-xquery-20040723/#XMLSchema)] Part 1, Section 2.2.2.2. 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 substitution
The use of a value whose actual type is derived from the expected type is known as subtype substitution.
symbol
Each rule in the grammar defines one symbol, in the form
target namespace
Each imported schema or module is identified by its target namespace, which is the namespace of the objects (such as elements or functions) that are defined by the schema or module.
terminal
A terminal is a single unit of the grammar that can not be further subdivided, and is specified in the EBNF by a character or characters in quotes, or a regular expression.
type error
A type error may be raised during the analysis or evaluation phase. During the analysis phase, a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) occurs when the static type (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type) of an expression does not match the expected type of the context in which the expression occurs. During the evaluation phase, a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) occurs when the dynamic type of a value does not match the expected type of the context in which the value occurs.
type promotion
Under certain circumstances, an atomic value can be promoted from one type to another. Type promotion is used in function calls (see 3.1.5 Function Calls) and in processing of operators that accept numeric operands (see B.2 Operator Mapping).
user-defined function
For a user-defined function, the function declaration includes an expression called the function body that defines how the result of the function is computed from its parameters.
variable values
Variable values. This is a set of (expanded QName, value) pairs. It contains the same expanded QNames (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-expanded-qname) as the in-scope variables (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-in-scope-variables) in the static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context) for the expression. The QName is the name of the variable and the value is the dynamic value of the variable.
version declaration
Any module resource (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-module-resource) may contain a version declaration. If present, the version declaration occurs at the beginning of the module resource (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-module-resource) and identifies the applicable XQuery syntax and semantics for the module resource (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-module-resource).
Whitespace
Whitespace characters are defined by [http://www.w3.org/TR/REC-xml#NT-S [1] (http://www.w3.org/TR/REC-xml#NT-S)] when these characters occur outside of a StringLiteral (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-StringLiteral).
xdt:anyAtomicType
xdt:anyAtomicType includes all atomic values (and no values that are not atomic).
xdt:dayTimeDuration
xdt:dayTimeDuration is a subtype of xs:duration whose lexical representation is restricted to contain only day, hour, minute, and second components.
xdt:untyped
xdt:untyped is used to denote the dynamic type of an element node that has not been validated, or has been validated in skip mode.
xdt:untypedAtomic
xdt:untypedAtomic is used to denote untyped atomic data, such as text that has not been assigned a more specific type.
xdt:yearMonthDuration
xdt:yearMonthDuration is a subtype of xs:duration whose lexical representation is restricted to contain only year and month components.
xmlspace declaration
The xmlspace declaration in a Prolog (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-prolog) controls whether boundary whitespace (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-boundary-whitespace) is preserved by direct element constructors (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-direct-elem-const) during execution of the query.
XML space policy
XMLSpace policy. This policy, declared in the Prolog, controls the processing of whitespace by element constructors.
XPath 1.0 compatibility mode
XPath 1.0 compatibility mode. This component must be set by all host languages that include XPath 2.0 as a subset, indicating whether rules for compatibility with XPath 1.0 are in effect. XQuery sets the value of this component to false.
XQuery Flagger
An XQuery Flagger is a facility that is provided by an implementation that is able to identify queries that contain must-understand extensions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-must-understand). If an implementation supports must-understand extensions, then an XQuery Flagger must be provided.
XQuery static flagger
An XQuery Static Flagger is a facility that is able to identify queries that require a static typing extension (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-typing-extension).
F Summary of Error Conditions (Non-Normative)
err:XP0001
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if analysis of an expression relies on some component of the static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context) that has not been assigned a value.
err:XP0002
It is a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) if evaluation of an expression relies on some part of the dynamic context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-context) that has not been assigned a value.
err:XP0003
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if an expression is not a valid instance of the grammar defined in A.1 EBNF.
err:XP0004
During the analysis phase, it is a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) if the static typing feature is in effect and an expression is found to have a static type that is not appropriate for the context in which the expression occurs.
err:XP0005
During the analysis phase, it is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if the static typing feature is in effect and the static type assigned to an expression other than the expression () or data(()) is the empty type.
err:XP0006
During the evaluation phase, it is a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) if a value does not match a required type as specified by the matching rules in 2.4.4 SequenceType Matching.
err:XP0007
It is a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) if the fn:data function is applied to a node whose type annotation denotes a complex type with non-mixed complex content.
err:XP0008
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if an expression refers to an element name, attribute name, type name, function name, namespace prefix, or variable name that is not defined in the static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context), except within an ElementTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementTest) or an AttributeTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeTest).
err:XQ0009
An implementation that does not support the Schema Import Feature may raise a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if a prolog contains a schema import.
err:XQ0010
An implementation that does not support the Full Axis Feature (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-full-axis-feature) must raise a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if it encounters a reference to an optional axis (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-optional-axis) that it does not support.
err:XQ0012
If the Schema Import Feature is in effect, it is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if the set of definitions contained in all imported schemas do not satisfy the conditions for schema validity specified in Sections 3 and 5 of [XML Schema (http://www.w3.org/TR/2004/WD-xquery-20040723/#XMLSchema)] Part 1. In particular, the definitions must be valid, they must be complete, and they must be unique -- that is, the pool of definitions must not contain two or more schema components with the same name and target namespace.
err:XQ0013
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if an implementation supports a pragma but determines that its content is invalid.
err:XQ0014
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if an implementation does not support a must-understand extension or an implementation does support a must-understand extension and the implementation determines that the character content is invalid.
err:XQ0015
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if the XQuery Flagger is enabled and the query contains a must-understand extension.
err:XQ0016
An implementation that does not support the Module Feature raises a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if it encounters a module declaration (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-module-declaration) or a module import (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-module-import).
err:XP0017
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if the expanded QName and number of arguments in a function call do not match the name and arity of a function signature (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-function-signature) in the static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context).
err:XP0018
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) for an expression to depend on the focus when the focus is undefined.
err:XP0019
It is a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) if the result of a step expression (StepExpr) is not a (possibly empty) sequence of nodes.
err:XP0020
It is a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) if in an axis expression, the context item is not a node.
err:XP0021
It is a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) if the argument of a cast expression or constructor function cannot be cast to the required type.
err:XQ0022
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if the value of a namespace declaration attribute (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-namespace-decl-attr) is not a literal string.
err:XQ0023
(Not currently used.)
err:XQ0024
It is a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) if the content sequence in an element constructor contains an attribute node following a node that is not an attribute node.
err:XQ0025
It is a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) if any attribute of a constructed element does not have a name that is distinct from the names of all other attributes of the constructed element.
err:XQ0026
It is a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) if the result of either the name expression or the content expression of a computed processing instruction constructor contains the string "?>".
err:XQ0027
In a validate expression, it is a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) if validation fails.
err:XQ0028
(Not currently used.)
err:XP0029
It is a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) in a cast expression if the input value does not satisfy the facets of the target type.
err:XQ0030
It is a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) if the argument of a validate expression does not evaluate to exactly one document or element node.
err:XQ0031
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if the version number specified in a version declaration is not supported by the implementation.
err:XQ0032
A static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) is raised if a prolog contains multiple declarations for the base URI.
err:XQ0033
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if a prolog contains multiple declarations for the same namespace prefix.
err:XQ0034
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if multiple functions declared or imported by a module resource (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-module-resource) have the same expanded QName and the same number of arguments.
err:XQ0035
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) to import two schema components that both define the same name in the same symbol space and in the same scope.
err:XQ0036
It is a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) to import a module if the importing module's in-scope type definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-types) do not include definitions for the type names that appear in variable declarations, function parameters, or function returns found in the imported module.
err:XQ0037
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) to import a module that contains function declarations or variable declarations whose names are already declared in the static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context) of the importing module.
err:XQ0038
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if a prolog specifies more than one default collation, or value specified does not identify a collation known to the implementation.
err:XQ0039
It is an static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) for a function declaration to have more than one parameter with the same name.
err:XQ0040
It is an static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if the attributes specified by a direct element constructor do not have distinct names.
err:XQ0041
It is a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) if the value of the name expression in a computed processing instruction constructor cannot be cast to the type xs:NCName.
err:XQ0042
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if a computed element constructor contains more than one content expression, or if it contains a local namespace declaration (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-local-namespace-decl) following a content expression.
err:XQ0043
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if two or more local namespace declarations (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-local-namespace-decl) within the same computed element constructor have same namespace prefix or have no namespace prefix.
err:XQ0044
It is a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) if the name expression of a computed attribute constructor returns a QName that is in the namespace http://www.w3.org/TR/REC-xml-names (corresponding to namespace prefix xmlns), or returns a QName that is in no namespace and has local name xmlns.
err:XQ0045
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if the function name in a function declaration is in one of the following namespaces: http://www.w3.org/XML/1998/namespace, http://www.w3.org/2001/XMLSchema, http://www.w3.org/2001/XMLSchema-instance, http://www.w3.org/2004/07/xpath-functions, http://www.w3.org/2004/07/xpath-datatypes.
err:XQ0046
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if a string that is required to contain a valid URI does not contain a valid lexical form according to the definition of xs:anyURI in [XML Schema (http://www.w3.org/TR/2004/WD-xquery-20040723/#XMLSchema)].
err:XQ0047
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if multiple module imports in the same Prolog specify the same target namespace.
err:XQ0048
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if a function or variable declared in a library module is not in the target namespace of the library module.
err:XQ0049
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if more than one variable declared or imported by a module resource (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-module-resource) has the same expanded QName.
err:XP0050
It is a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) if the dynamic type of the operand of a treat expression does not match the type specified by the treat expression.
err:XP0051
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if a QName that is used as an AtomicType (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AtomicType) in a SequenceType (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SequenceType) is not defined in the in-scope type definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-types) as an atomic type.
err:XQ0052
It is a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) if the content of a node constructor includes an atomic value that cannot be cast into a string, such as a value of type xs:QName or xs:NOTATION.
err:XQ0053
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if the string literal used in a namespace declaration to specify a URI is a zero-length string, and the implementation does not support [XML Names 1.1 (http://www.w3.org/TR/2004/WD-xquery-20040723/#XMLNAMES11)].
err:XQ0054
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if the initializing expression (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-initializing-expression) in a variable declaration cannot be executed because of a circularity (for example, the expression depends on a function that in turn depends on the value of the initialized variable).
err:XP0055
(Not currently used.)
err:XQ0056
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if the target namespace specified in a module import is the same as the target namespace of the importing module.
err:XQ0057
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if a schema import binds a namespace prefix but does not specify a target namespace other than a zero-length string.
err:XQ0058
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if multiple schema imports specify the same target namespace.
err:XQ0059
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if an implementation is unable to process a schema or module import by finding a schema or module with the specified target namespace.
err:XQ0060
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if the name of a function in a function declaration is not in a namespace (expanded QName has an empty URI).
err:XQ0061
It is a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) if validity assessment is performed on a document node unless the children of the document node comprise exactly one element node, no text nodes, and zero or more comment and processing instruction nodes, in any order.
err:XQ0062
It is a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) if a document-level constraint is not satisfied when validity assessment is performed on a document node. Document-level constraints include identity constraints (xs:unique, xs:key, and xs:keyref) and ID/IDREF constraints.
err:XQ0063
It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) if the URI specified by a default function namespace declaration is a zero-length string.
err:XQ0064
It is a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) if the value of the name expression in a computed processing instruction constructor is equal to "XML" (in any combination of upper and lower case).
err:XQ0065
A static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) is raised if a prolog contains multiple default ordering declarations.
err:XQ0066
A static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) is raised if a prolog contains more than one default element/type namespace declaration, or more than one default function namespace declaration.
err:XQ0067
A static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) is raised if a prolog contains multiple construction declarations.
G Example Applications (Non-Normative)
This section contains examples of several important classes of queries that can be expressed using XQuery. The applications described here include joins across multiple data sources, grouping and aggregation, queries based on sequential relationships, recursive transformations, and selection of distinct combinations of values.
G.1 Joins
Joins, which combine data from multiple sources into a single result, are a very important type of query. In this section we will illustrate how several types of joins can be expressed in XQuery. We will base our examples on the following three documents:
A document named parts.xml that contains many part elements; each part element in turn contains partno and description subelements.
A document named suppliers.xml that contains many supplier elements; each supplier element in turn contains suppno and suppname subelements.
A document named catalog.xml that contains information about the relationships between suppliers and parts. The catalog document contains many item elements, each of which in turn contains partno, suppno, and price subelements.
A conventional ("inner") join returns information from two or more related sources, as illustrated by the following example, which combines information from three documents. The example generates a "descriptive catalog" derived from the catalog document, but containing part descriptions instead of part numbers and supplier names instead of supplier numbers. The new catalog is ordered alphabetically by part description and secondarily by supplier name.
<descriptive-catalog>
{
for $i in fn:doc("catalog.xml")//item,
$p in fn:doc("parts.xml")//part[partno = $i/partno],
$s in fn:doc("suppliers.xml")//supplier[suppno = $i/suppno]
order by $p/description, $s/suppname
return
<item>
{
$p/description,
$s/suppname,
$i/price
}
</item>
}
</descriptive-catalog>
The previous query returns information only about parts that have suppliers and suppliers that have parts. An outer join is a join that preserves information from one or more of the participating sources, including elements that have no matching element in the other source. For example, a left outer join between suppliers and parts might return information about suppliers that have no matching parts.
The following query demonstrates a left outer join. It returns names of all the suppliers in alphabetic order, including those that supply no parts. In the result, each supplier element contains the descriptions of all the parts it supplies, in alphabetic order.
for $s in fn:doc("suppliers.xml")//supplier
order by $s/suppname
return
<supplier>
{
$s/suppname,
for $i in fn:doc("catalog.xml")//item
[suppno = $s/suppno],
$p in fn:doc("parts.xml")//part
[partno = $i/pno]
order by $p/description
return $p/description
}
</supplier>
The previous query preserves information about suppliers that supply no parts. Another type of join, called a full outer join, might be used to preserve information about both suppliers that supply no parts and parts that have no supplier. The result of a full outer join can be structured in any of several ways. The following query generates a list of supplier elements, each containing nested part elements for the parts that it supplies (if any), followed by a list of part elements for the parts that have no supplier. This might be thought of as a "supplier-centered" full outer join. Other forms of outer join queries are also possible.
<master-list>
{
for $s in fn:doc("suppliers.xml")//supplier
order by $s/suppname
return
<supplier>
{
$s/suppname,
for $i in fn:doc("catalog.xml")//item
[suppno = $s/suppno],
$p in fn:doc("parts.xml")//part
[partno = $i/partno]
order by $p/description
return
<part>
{
$p/description,
$i/price
}
</part>
}
</supplier>
,
(: parts that have no supplier :)
<orphan-parts>
{ for $p in fn:doc("parts.xml")//part
where fn:empty(fn:doc("catalog.xml")//item
[partno = $p/partno] )
order by $p/description
return $p/description
}
</orphan-parts>
}
</master-list>
The previous query uses an element constructor to enclose its output inside a master-list element. The concatenation operator (",") is used to combine the two main parts of the query. The result is an ordered sequence of supplier elements followed by an orphan-parts element that contains descriptions of all the parts that have no supplier.
G.2 Grouping
Many queries involve forming data into groups and applying some aggregation function such as fn:count or fn:avg to each group. The following example shows how such a query might be expressed in XQuery, using the catalog document defined in the previous section.
This query finds the part number and average price for parts that have at least 3 suppliers.
for $pn in fn:distinct-values(fn:doc("catalog.xml")//partno)
let $i := fn:doc("catalog.xml")//item[partno = $pn]
where fn:count($i) >= 3
order by $pn
return
<well-supplied-item>
<partno> {$p} </partno>
<avgprice> {fn:avg($i/price)} </avgprice>
</well-supplied-item>
The fn:distinct-values function in this query eliminates duplicate part numbers from the set of all part numbers in the catalog document. The result of fn:distinct-values is a sequence in which order is not significant.
Note that $pn, bound by a for clause, represents an individual part number, whereas $i, bound by a let clause, represents a set of items which serves as argument to the aggregate functions fn:count($i) and fn:avg($i/price). The query uses an element constructor to enclose each part number and average price in a containing element called well-supplied-item.
The method illustrated above generalizes easily to grouping by more than one data value. For example, consider a census document containing a sequence of person elements, each with subelements named state, job, and income. A census analyst might need to prepare a report listing the average income for each combination of state and job. This report might be produced using the following query:
for $s in fn:distinct-values(fn:doc("census.xml")//state),
$j in fn:distinct-values(fn:doc("census.xml")//job)
let $p := fn:doc("census.xml")//person[state = $s and job = $j]
order by $s, $j
return
if (fn:exists($p)) then
<group>
<state> {$s} </state>
<job> {$j} </job>
<avgincome> {fn:avg($p/income)} </avgincome>
</group>
else ()
The if-then-else expression in the above example prevents generation of groups that contain no data. For example, the census data may contain some persons who live in Nebraska, and some persons whose job is Deep Sea Fisherman, but no persons who live in Nebraska and have the job of Deep Sea Fisherman. If output groups are desired for all possible combinations of states and jobs, the if-then-else expression can be omitted from the query. In this case, the output may include "empty" groups such as the following:
<group>
<state>Nebraska</state>
<job>Deep Sea Fisherman</state>
<avgincome/>
</group>
G.3 Queries on Sequence
XQuery uses the << and >> operators to compare nodes based on document order. Although these operators are quite simple, they can be used to express complex queries for XML documents in which sequence is meaningful. The first two queries in this section involve a surgical report that contains procedure, incision, instrument, action, and anesthesia elements.
The following query returns all the action elements that occur between the first and second incision elements inside the first procedure. The original document order among these nodes is preserved in the result of the query.
let $proc := //procedure[1]
for $i in $proc//action
where $i >> ($proc//incision)[1]
and $i << ($proc//incision)[2]
return $i
It is worth noting here that document order is defined in such a way that a node is considered to precede its descendants in document order. In the surgical report, an action is never part of an incision, but an instrument is. Since the >> operator is based on document order, the predicate $i >> ($proc//incision)[1] is true for any instrument element that is a descendant of the first incision element in the first procedure.
For some queries, it may be helpful to define a function that can test whether a node precedes another node without being its ancestor. The following function returns true if its first operand precedes its second operand but is not an ancestor of its second operand; otherwise it returns false:
declare function local:precedes($a as node(), $b as node())
as boolean
{
$a << $b
and
fn:empty($a//node() intersect $b)
};
Similarly, a local:follows function could be written:
declare function local:follows($a as node(), $b as node())
as boolean
{
$a >> $b
and
fn:empty($b//node() intersect $a)
};
Using the local:precedes function, we can write a query that finds instrument elements between the first two incisions, excluding from the query result any instrument that is a descendant of the first incision:
let $proc := //procedure[1]
for $i in $proc//instrument
where local:precedes(($proc//incision)[1], $i)
and local:precedes($i, ($proc//incision)[2])
return $i
The following query reports incisions for which no prior anesthesia was recorded in the surgical report. Since an anesthesia is never part of an incision, we can use << instead of the less-efficient local:precedes function:
for $proc in //procedure
where some $i in $proc//incision satisfies
fn:empty($proc//anesthesia[. << $i])
return $proc
In some documents, particular sequences of elements may indicate a logical hierarchy. This is most commonly true of HTML. The following query returns the introduction of an XHTML document, wrapping it in a div element. In this example, we assume that an h2 element containing the text "Introduction" marks the beginning of the introduction, and the introduction continues until the next h2 or h1 element, or the end of the document, whichever comes first.
let $intro := //h2[text()="Introduction"],
$next-h := //(h1|h2)[. >> $intro][1]
return
<div>
{
$intro,
if (fn:empty($next-h))
then //node()[. >> $intro]
else //node()[. >> $intro and . << $next-h]
}
</div>
Note that the above query makes explicit the hierarchy that was implicit in the original document. In this example, we assume that the h2 element containing the text "Introduction" has no subelements.
G.4 Recursive Transformations
Occasionally it is necessary to scan over a hierarchy of elements, applying some transformation at each level of the hierarchy. In XQuery this can be accomplished by defining a recursive function. In this section we will present two examples of such recursive functions.
Suppose that we need to compute a table of contents for a given document by scanning over the document, retaining only elements named section or title, and preserving the hierarchical relationships among these elements. For each section, we retain subelements named section or title; but for each title, we retain the full content of the element. This might be accomplished by the following recursive function:
declare function local:sections-and-titles($n as node()) as node()?
{
if (fn:local-name($n) = "section")
then element
{ fn:local-name($n) }
{ for $c in $n/* return local:sections-and-titles($c) }
else if (fn:local-name($n) = "title")
then $n
else ( )
};
The "skeleton" of a given document, containing only its sections and titles, can then be obtained by invoking the local:sections-and-titles function on the root node of the document, as follows:
local:sections-and-titles(fn:doc("cookbook.xml"))
As another example of a recursive transformation, suppose that we wish to scan over a document, transforming every attribute named color to an element named color, and every element named size to an attribute named size. This can be accomplished by the following recursive function:
declare function local:swizzle($n as node()) as node()
{
typeswitch($n)
case $a as attribute(color)
return element color { fn:string($a) }
case $es as element(size)
return attribute size { fn:string($es) }
case $e as element()
return element
{ fn:local-name($e) }
{ for $c in $e/(* | @*) return local:swizzle($c) }
case $d as document-node()
return document
{ for $c in $d/* return local:swizzle($c) }
default return $n
};
The transformation can be applied to a whole document by invoking the local:swizzle function on the root node of the document, as follows:
local:swizzle(fn:doc("plans.xml"))
G.5 Selecting Distinct Combinations
It is sometimes necessary to search through a set of data to find all the distinct combinations of a given list of properties. For example, an input data set might consist of a large set of order elements, each of which has the same basic structure, as illustrated by the following example:
<order>
<date>2003-10-15</date>
<product>Dress Shirt</product>
<size>M</size>
<color>Blue</color>
<supplier>Fashion Trends</supplier>
<quantity>50</quantity>
</order>
From this data set, a user might wish to find all the distinct combinations of product, size, and color that occur together in an order. The following query returns this list, enclosing each distinct combination in a new element named option:
for $p in fn:distinct-values(//product),
$s in fn:distinct-values(//size),
$c in fn:distinct-values(//color)
order by $p, $s, $c
return
if (fn:exists(//order[product eq $p
and size eq $s and color eq $c]))
then
<option>
<product>{$p}</product>
<size>{$s}</size>
<color>{$c}</color>
</option>
else ()
H XPath 2.0 and XQuery 1.0 Issues (Non-Normative)
The XPath 2.0 and XQuery 1.0 Issues List that records pre-Last Call issues can be found at http://www.w3.org/XML/2003/11/xpath-xquery-issues (http://www.w3.org/XML/2003/11/xpath-xquery-issues).
I Revision Log (Non-Normative)
This log records the changes that have been made to this document since the Last Call Draft of 12 November 2003.
I.1 23 July 2004
An ordering declaration has been added to the Prolog, which affects the ordering semantics of path expressions, FLWOR expressions, and union, intersect, and except expressions. In addition, ordered and unordered operators have been introduced that permit ordering semantics to be controlled at the expression level within a query.
The SequenceType syntax has been simplified. SchemaContextPath is no longer part of the SequenceType syntax. Also, the section on SequenceType Matching has been rewritten to make its terminology more consistent with the Formal Semantics document.
Validation has been separated from construction. Validation now occurs only as a result of an explicit validate expression. Validation modes are strict and lax, and are specified on the validate expression. New construction modes strip and preserve have been defined and are declared in the Prolog. The notion of "validation context" has been deleted. The XQuery definition of validation has been converged with the definition used in XSLT.
It is now permitted for multiple user-defined functions to have the same name as long as they have different numbers of arguments.
The term xdt:untypedAny is changed to xdt:untyped.
xs:anyType is no longer an abstract type, but is now used to denote the type of a partially validated element node. Since there is no longer a meaningful distinction between abstract types and concrete types, these terms are no longer used in this document.
Value comparisons now return () if either operand is ().
Computed namespace constructors are now completely static and are allowed only inside a computed element constructor. Namespace declarations in a computed element constructor must come before the element content, and must consist entirely of literals. The namespace prefix is optional. If absent, it has the effect of setting the default namespace for elements and types within the scope of the constructed element.
The name of the Predicates grammar production has been changed to PredicateList.
Grammar changes have been made in the Prolog, including constraints on the order of declarations and imports.
The grammar production formerly called a FilterStep is now called a FilterExpression and is described in a separate section rather than as part of a path expression.
The precedence of the cast and treat operators in the grammar has been increased.
The precedence of unary arithmetic operators has been increased.
The syntax for variable initialization in the Prolog now uses an assignment operator (":="). Also, circularities in variable initialization are now considered to be a static errors.
The appendix containing a list of error messages has been made non-normative.
An error is raised if a module attempts to import itself (target namespace of importing module and imported modules are the same).
A schema can now be imported without specifying either a target namespace or a location hint.
Module imports and schema imports now accept multiple location hints, representing multiple physical resources in the same module or schema.
CData Sections are no longer considered to be constructors, but are simply a notational convenience for embedding special characters in the content of an element or attribute constructor.
Three new components have been added to the static context: XQuery Flagger status, XQuery Static Flagger status, and context item static type.
The expression data(()) no longer raises a static error, although its static type is empty.
If a dynamic implementation detects a static error, the evaluation phase is optional.
XPath allows host languages to specify whether they recognize the concept of a namespace node. XQuery does not recognize namespace nodes. Instead, it recognizes an "in-scope namespaces" property of an element node.
The specification now clearly distinguishes between "statically-known namespaces" (a static property of an expression) and "in-scope namespaces" (a dynamic property of an element).
An order by clause may now accept values of mixed type if they have a common type that is reachable by numeric promotion and/or moving up the type derivation hierarchy, and if this common type has a gt operator.
In element and document node constructors, if the content sequence contains a document node, that node is replaced by its children (this was previously treated as an error).
Atomization now applies to the name expression of a computed processing instruction constructor.
It is now implementation-defined whether undeclaration of namespace prefixes in an element constructor is supported. If supported, this feature conforms to the semantics of Namespaces 1.1. In other words, if an element constructor binds a namespace prefix to the zero-length string, any binding of that prefix defined at an outer level is suspended within the scope of the constructed element.
The names of certain components in the static and dynamic contexts have been changed to make them more consistent and descriptive.
In a computed text node constructor, the expression enclosed in curly braces is no longer optional, since it is not possible to construct an empty text node.
The definition of the idiv operator has been made consistent with the Functions and Operators document. The idiv operator accepts operands of any numeric types, performs a division, and truncates the result to an integer.
Certain grammar productions have been renamed and reordered to make the grammar easier to read.
The section on constructor functions has been edited to make it more consistent with the definition of constructor functions in the Functions and Operators document.
The Comments section has been moved out of the Primary Expressions section, because a comment is not a primary expression.
The term "module resource" has been introduced to represent a fragment of XQuery code that can independently undergo static analysis. A module may comprise several module resources. Each module resource has its own static and dynamic context.
Rules for processing comment constructors have changed, to ensure that the resulting comment does not contain adjacent hyphens or end with a hyphen.
Some additional constraints have been added to the section titled "Consistency Constraints".
Various minor changes, both editorial and substantive, have been made in response to public comments and working group discussions.


