XQuery 1.0:XML查询语言 工作草案-2

TransWiki - an Open Translation Project(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


Table of contents

2.1 2.1 Expression Context
2.2 2.1 表达式语境

2.3 2.2 Processing Model
2.4 2.2 处理模型

2.5 2.3 Documents
2.6 2.3 文档

2.7 2.4 Types

2.8 2.5 Error Handling
2.9 2.5 错误处理

2.10 2.6 Optional Features
2.11 2.6 可选特征

2.12 2.7 Comments
2.13 2.7 注释

2 Basics

2 基础

The basic building block of XQuery is the expression, which is a string of Unicode characters. This specification makes no assumptions or requirements regarding the character set encoding of strings of Unicode characters. The language provides several kinds of expressions which may be constructed from keywords, symbols, and operands. In general, the operands of an expression are other expressions. [Definition: 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.)] [Definition: XQuery is also a strongly-typed language in which the operands of various expressions, operators, and functions must conform to the expected types.]
XQuery的基石是表达式,即Unicode字符组成的字符串。本规范没有对Unicode字符组成的字符串的字符集编码(character set encoding)做出任何假定或者要求。XQuery提供了几种类型的表达式,它们可以由关键字(keywords)、符号(symbols)以及操作数(operand)构造而来。一般来说,一个表达式的操作数是另一个表达式。[定义:XQuery是一种函数式语言(functional language),这意味着表达式可以普遍地嵌套。(但是,与一个纯正的函数式语言不同的是,如果变量的声明中包含有新节点的构造式,它不支持变量的可替换性(substitutability)。)] [定义:XQuery也是一种强类型语言(strongly-typed language),其中各种表达式、运算符和函数的操作数都必须遵从期望的类型。]

Note:
This specification contains no assumptions or requirements regarding the character set encoding of strings of Unicode characters.
注意:
本规范并没有对Unicode字符组成的字符串的字符集编码(character set encoding)做出任何假定或者要求。
Like XML, XQuery is a case-sensitive language. Keywords in XQuery use lower-case characters and are not reserved—that is, names in XQuery expressions are allowed to be the same as language keywords—except for the list of reserved function-names in A.3 Reserved Function Names.
与XML一样,XQuery也是一种对大小写敏感的语言。XQuery中的关键字用小写字符并且没有保留——也就是说,XQuery表达式中的名称可以与语言中的关键字相同——在A.3 保留的函数名中列出的保留的函数名除外。
The value of an expression is always a sequence (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-sequence). [Definition: A sequence is an ordered collection of zero or more items (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-item).] [Definition: 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).] [Definition: 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).] [Definition: 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)].] Each node has a unique node identity. Some kinds of nodes have typed values, string values, and names, which can be extracted from the node. The typed value of a node is a sequence of zero or more atomic values. The string value of a node is a value of type xs:string. The name of a node is a value of type xs:QName.
一个表达式的值永远是一个序列 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-sequence)。[定义:一个序列是零或多个 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-item)(items)的一个有序集合。] [定义:一个是一个原子值 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-atomic-value)(atomic value)或者一个节点 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-node)(node)] [定义:一个原子值是一种原子类型(atomic type)的值域中的一个值,包括 [XML Schema (http://www.w3.org/TR/2004/WD-xquery-20040723/#XMLSchema)] 和xdt:untypedAtomic (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-untypedAtomic) 中定义的所有原子类型。] [定义:一个节点[XQuery 1.0 and XPath 2.0 Data Model (http://www.w3.org/TR/2004/WD-xquery-20040723/#datamodel)] 中定义的节点类型(node kinds)中的一种类型的一个实例。]每个节点有一个唯一的节点标识(node identity)。有些类型的节点有类型(typed values)、字符串值(string values)和名称,这些可以从节点中抽取出来。一个节点的类型值是零个或多个原子值的一个序列。一个节点的字符串值是 xs:string 类型的值。一个节点的名称是 xs:QName 类型的值。
[Definition: A sequence containing exactly one item is called a singleton sequence.] An item is identical to a singleton sequence containing that item. Sequences are never nested—for example, combining the values 1, (2, 3), and ( ) into a single sequence results in the sequence (1, 2, 3). [Definition: A sequence containing zero items is called an empty sequence.]
[定义:仅仅包含一个项的序列称为单元素序列(singleton sequence)。]一个项与包含该项的单元素序列是等价的。序列从不嵌套——例如,将值1,(2,3)和()合并到一个序列中得到序列(1,2,3)。[定义:包含零个项的序列称为空序列(empty sequence)。]
Names in XQuery are called QNames, and conform to the syntax in [XML Names (http://www.w3.org/TR/2004/WD-xquery-20040723/#XMLNAMES)]. [Definition: Lexically, a QName consists of an optional namespace prefix and a local name.] A lexical QName can be converted into an expanded QName by resolving its namespace prefix, using algorithms described later in this document. [Definition: An expanded QName consists of an optional namespace URI and a local name.] Two QNames are considered equal if their namespace URIs are equal and their local names are equal (even if the prefixes in their lexical forms are not equal). Namespace URIs and local names are compared on a codepoint basis, without normalization.
XQuery中的名称称为QNames,并且遵从[XML Names (http://www.w3.org/TR/2004/WD-xquery-20040723/#XMLNAMES)]中定义的语法。[定义:从词法上说,一个QName由一个可选的命名空间前缀和内部名称(local name)组成。]通过用本文档后文描述的方法解析命名空间前缀,一个词法上的QName可以来被转换成为扩展的QName(expanded QName)。[定义:一个扩展的QName由一个可选的命名空间URI和一个内部名称组成。]如果两个QName的命名空间URI相等而且内部名也是相等(即使它们词法形式上的前缀不同),就认为它们是相等的。命名空间URI和内部名在码点(codepoint)的基础上进行比较,无需经过规范化。
This document uses the following predefined namespace prefixes:
本文档用到了如下预定义的命名空间前缀:


xs = http://www.w3.org/2001/XMLSchema


xsi = http://www.w3.org/2001/XMLSchema-instance


fn = http://www.w3.org/2004/07/xpath-functions


xdt = http://www.w3.org/2004/07/xpath-datatypes


local = http://www.w3.org/2004/07/xquery-local-functions (见 4.13 函数声明.)
In some cases, where the meaning is clear and namespaces are not important to the discussion, built-in XML Schema typenames such as integer and string are used without a namespace prefix.
在有些情形下,含义清楚而且命名空间对于讨论无关紧要,这时内置的XML Schema类型名如 integer 和 string 使用时不带命名空间前缀。
Element nodes have a property called in-scope namespaces. [Definition: 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.]
元素节点有一个称为作用域内命名空间的属性。[定义:一个元素节点的作用域内命名空间是一个命名空间绑定的集合,每个绑定都将一个命名空间前缀关联到一个URI,从而定义了解析元素作用域内QName时用到的命名空间前缀集。对于某一给定的元素,一个命名空间绑定可能有空前缀。这个命名空间绑定的URI就是该元素作用域内的默认命名空间。]
Note:
注意:
In [XPath 1.0 (http://www.w3.org/TR/2004/WD-xquery-20040723/#XPath)], the in-scope namespaces of an element node are represented by a collection of namespace nodes arranged on a namespace axis, which is optional and deprecated in [XPath 2.0 (http://www.w3.org/TR/2004/WD-xquery-20040723/#XPath20)]. XQuery does not support the namespace axis and does not represent namespace bindings in the form of nodes. However, where other specifications such as [XSLT 2.0 and XQuery 1.0 Serialization (http://www.w3.org/TR/2004/WD-xquery-20040723/#serialization)] refer to namespace nodes, these nodes may be synthesized from the in-scope namespaces of an element node by interpreting each namespace binding as a namespace node.
[XPath 1.0 (http://www.w3.org/TR/2004/WD-xquery-20040723/#XPath)] 中,一个元素节点的作用域内命名空间(in-scope namespaces)是用一序列按照命名空间轴(namespace axis)排列的命名空间节点(namespace nodes)表示的。在[XPath 2.0 (http://www.w3.org/TR/2004/WD-xquery-20040723/#XPath20)] 中这是可选的而且是不提倡的。XQuery不支持命名空间轴,也不用节点的形式表示命名空间绑定。然而,当其它的规范如 [XSLT 2.0 and XQuery 1.0 Serialization (http://www.w3.org/TR/2004/WD-xquery-20040723/#serialization)] 提到命名空间节点时,这些节点可能是通过将每个命名空间绑定解释为一个命名空间节点,从而由一个元素节点的作用域内命名空间产生的。

2.1 Expression Context

2.1 表达式语境

[Definition: The expression context for a given expression consists of all the information that can affect the result of the expression.] This information is organized into two categories called the static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context) and the dynamic context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-context).
[定义:一个特定表达式的表达式语境由所有能够影响该表达式结果的信息组成。]这些信息被组织到两个类别中,分别称为静态语境(static context)和动态语境(dynamic context)。

2.1.1 Static Context

2.1.1 静态语境

[Definition: The static context of an expression is the information that is available during static analysis of the expression, prior to its evaluation.] This information can be used to decide whether the expression contains a static error (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, a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) is raised.[err:XP0001 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0001)]
[定义:一个表达式的静态语境是指表达式求值前的静态分析时可用的信息。]这些信息能够用来判断表达式是否包含静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)(static error)。如果表达式的分析依赖于静态语境 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context)的某些尚未赋值的构件,就会引起一个静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)。[err:XP0001 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0001)]
The individual components of the static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context) are summarized below. Further rules governing the semantics of these components can be found in C.1 Static Context Components.
静态语境 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context)的各构件总结如下。控制这些构件的语义的更多规则可以参看C.1 静态语境成分


[Definition: 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. ]
[定义:XPath 1.0兼容方式。所有将XPath 2.0作为一个子集包含在内的宿主语言都必须设置这个构件,它指示了保证与XPath 1.0兼容的规则是否起作用。XQuery将这个构件的值设为 false。]


[Definition: 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.] Note the difference between in-scope namespaces (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-in-scope-namespaces), which is a dynamic property of an element node, and statically known namespaces (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-namespaces), which is a static property of an expression.
[定义:静态已知命名空间(Statically known namespaces)。它是(前缀,URI)对的集合,这些(前缀,URI)对定义了给定表达式静态处理时已知的命名空间。]注意作用域内命名空间 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-in-scope-namespaces)(in-scope namespace)与静态已知命名空间 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-namespaces)的区别,前者是一个元素节点的动态属性(property),而后者则是一个表达式的静态属性(property)。
Some namespaces are predefined; additional namespaces can be added to the statically known namespaces by namespace declarations (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-namespace-declaration) in a Prolog (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-prolog), by namespace declaration attributes (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-namespace-decl-attr) in direct element constructors (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-direct-elem-const), and by local namespace declarations (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-local-namespace-decl) in computed element constructors (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-computed-elem-const).
有些命名空间是预定义的;附加的命名空间可以添加到静态已知命名空间里,通过 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-prolog)(Prolog)中的命名空间声明 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-namespace-declaration)(namespace declarations),通过直接元素构造器 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-direct-elem-const)(direct element constructors)的命名空间属性 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-namespace-decl-attr)(namespace declaration attributes),以及通过计算式元素构造器 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-computed-elem-const)(computed element constructors)里的本地命名空间声明 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-local-namespace-decl)(local namespace declarations )。


[Definition: 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.] The initial default element/type 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).
[定义:缺省元素/类型命名空间。这是一个命名空间URI或者“none”。该命名空间URI如果存在的话,在期望出现元素或类型名的地方,用于这些地方出现的任何无前缀的QName。]初始的缺省元素/类型命名空间可能在外部环境(external environmentor)中被 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-prolog)中的声明规定。


[Definition: 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).]
[定义:缺省函数命名空间。这个命名空间URI用于函数调用中作为函数名的任何无前缀的QName。初始的缺省函数命名空间可能在外部环境中被 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-prolog)中的声明规定。]


[Definition: 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.] It includes the following three parts:
[定义:作用域内模式定义(In-scope schema definitions)。这是一个通用的术语,适用于表达式处理时作用域内的所有元素、属性和类型定义。]它包括如下三个部分:


[Definition: 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 type definitions)。每个命名的类型定义要么被一个扩展的QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-expanded-qname)(对于一个命名类型(named type))标识,要么由一个依赖于实现 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent)的(implementation-dependent)类型标识符(对于匿名类型)标识。作用域内类型定义包括在2.4.1 预定义类型中描述的预定义类型。如果支持模式导入特征 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-schema-import-feature)(Schema Import Feature),作用域内类型定义也包括导入的模式中的所有类型定义。]


[Definition: 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. ] An element declaration includes information about the element's substitution group (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-substitution-group) affiliation.
[定义:作用域内元素声明(In-scope element declarations)。每个元素声明或者由一个扩展的QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-expanded-qname)(对于顶层的元素声明)标识,或者由依赖于实现的 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent)元素标识符(对于局部元素声明)标识。如果支持模式导入特征 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-schema-import-feature),作用域内元素声明包括导入的模式中所有的元素声明。]一个元素声明包括与附属的元素的置换组 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-substitution-group)(substitution group)相关的信息。
[Definition: 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.]
[定义:置换组[XML Schema (http://www.w3.org/TR/2004/WD-xquery-20040723/#XMLSchema)] Part 1,第2.2.2.2节中定义。非正式的说,以一个特定元素(称为头元素)开头的置换组由一组元素组成,这些元素可以替换头元素而不会影响模式验证的结果。]


[Definition: 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 attribute declarations)。每个属性声明或者由一个扩展的QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-expanded-qname)(对于顶层的属性声明)标识,或者由依赖于实现的 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent)属性标识符(对于局部元素声明)标识。如果支持模式导入特征 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-schema-import-feature),作用域内属性声明包括导入的模式中所有的属性声明。]


[Definition: 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.]
Variable declarations in a Prolog (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-prolog) are added to in-scope variables (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-in-scope-variables). An expression that binds a variable (such as a let, for, some, or every expression) extends the in-scope variables (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-in-scope-variables) of its subexpressions with the new bound variable and its type. Within a function declaration, the in-scope variables (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-in-scope-variables) are extended by the names and types of the function parameters.
[定义:作用域内变量(In-scope variables)。是一个(扩展的QName,类型)对的集合。它定义了一个表达式内可以引用的变量的集合。扩展的QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-expanded-qname)是变量名,类型是变量的静态类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type)。]
(http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-prolog)中的变量声明加入到了作用域内变量 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-in-scope-variables)中。一个绑定变量的表达式(如let、for、some或every表达式)用新的被绑定的变量及其类型扩充了该表达式的子表达式的作用域内变量 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-in-scope-variables)。在函数声明(function declaration)中,函数参数(function parameters)的名称和类型也扩充了作用域内变量 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-in-scope-variables)
The static type of a variable may be either declared in a query or (if the Static Typing Feature (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-typing-feature) is enabled) inferred by static type inference rules as described in [XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)].
一个变量的静态类型或者在查询中被声明(如果静态类型特征 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-typing-feature)被启用),或者由 [XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)] 描述的静态类型推理规则推理。


Context item static type. This component defines the static type of the context item within the scope of a given expression.
语境项静态类型(Context item static type)。这个构件定义了给定的表达式的作用域内语境项的静态类型。


[Definition: 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).] In addition to the name and arity, each function signature specifies the static types (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type) of the function parameters and result.
[定义:函数签名(Function signatures)。这个构件定义了一个表达式内可以调用的的函数的集合。每个函数唯一地用它的扩展QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-expanded-qname)和它的数量(arity)(参数的数目)标识。除了函数名和数量之外,每个函数签名规定了函数参数和其结果的静态类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type)。]
The function signatures (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-function-signature) include the signatures of constructor functions, which are discussed in 3.12.5 Constructor Functions.
函数签名 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-function-signature)包含构造器函数的签名,它们将在3.12.5构造器函数中讨论。


[Definition: 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.] A collation may be regarded as an object that supports two functions: a function that given a set of strings, returns a sequence containing those strings in sorted order; and a function that given two strings, returns true if they are considered equal, and false if not.
[定义:静态已知校对(Statically known collations)。它是(URI,校对)对的集合。它定义了带一个校对名作为参数的函数调用可用的校对名。]一个校对可以看作是一个支持两个函数的对象:一个函数是给定字符串集,返回排序后的字符串组成的序列;一个函数是给定两个字符串,如果它们相等,则返回真,否则返回假。


[Definition: 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 collation)。当没有明确指定校对时,它将静态已知校对 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-collations)中的一个校对确定为字符串比较函数和运算符使用的校对。]


[Definition: 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.]
[定义:构造方式(Construction mode)。构造方式控制元素构造器的行为。如果构造方式是preserve的,构造的元素节点的类型是xs:anyType,构造的元素的属性和后裔保持它们的原始类型。如果构造方式是strip,构造的元素节点和所有其后裔的类型都是xdt:untyped,构造的元素节点的属性的类型则是xdt:untypedAtomic。]


[Definition: 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.] Details are provided in the descriptions of these expressions.
[定义:排序方式(Ordering mode)。排序方式有两个值:ordered 和 unordered,它影响着路径表达式、union、intersect和except表达式以及不含order by子句的FLWOR表达式返回的结果序列的顺序。]细节见这些表达式的描述。


[Definition: XMLSpace policy. This policy, declared in the Prolog, controls the processing of whitespace by element constructors.] Its value may be preserve or strip.
[定义:XMLSpace策略(XMLSpace policy)。这个策略在序中声明,它控制着元素构造器(element constructors)对空白符的处理。]它的值是preserve 或 strip。


[Definition: Base URI. This is an absolute URI, used when necessary in the resolution of relative URIs (for example, by the fn:resolve-uri function.)]
[定义:基准URI(Base URI)。这是一个绝对的URI,需要时用于相对URI的解析(例如,fn:resolve-uri函数)中。]


[Definition: 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. ] If the argument to fn:doc is not a string literal that is present in statically known documents, then the static type (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type) of fn:doc is document-node()?.
[定义:静态已知文档(Statically known documents)。它是一个从字符串到类型的映射。字符串表示使用fn:doc函数时可能获得的资源的绝对URI。类型是以给定URI为字面参数(literal argument)对fn:doc的调用的类型。]如果传给fn:doc的参数不是静态已知文档中已经有的一个字符串(string literal),则fn:doc的静态类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type)是document-node()?
Note:
The purpose of the statically known documents is to provide static type information, not to determine which documents are available. A URI need not be found in the statically known documents to be accessed using fn:doc.
注意:
静态已知文档的目的是为了提供静态信息,而不是决定哪些文档是可用的。一个可以用 fn:doc 访问的URI并不一定要在静态已知文档中。


[Definition: 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.] If the argument to fn:collection is not a string literal that is present in statically known collections, then the static type (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type) of fn:collection is node()*.
[定义:静态已知集合(Statically known collections)。这是一个从字符串到类型的映射。字符串表示使用 fn:collection 函数可能获得的资源的绝对URI。类型指以这个URI为参数调用 fn:collection 函数时返回的节点序列的类型。]如果传给 fn:collection 的参数不是静态已知文档中已经有的一个字符串,则 fn:collection 的静态类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type)是node()*。]
Note:
The purpose of the statically known collections is to provide static type information, not to determine which collections are available. A URI need not be found in the statically known collections to be accessed using fn:collection.
注意:
静态已知集合的目的是为了提供静态信息,而不是决定哪些集合是可用的。一个可以用 fn:collection 访问的URI并不一定要在静态已知集合中。


XQuery Flagger status. This component has the value "on" if the XQuery Flagger is implemented and enabled; otherwise it has the value "off".
XQuery标志器状态(XQuery Flagger status)。如果XQuery Flagger被实现而且启用,这个构件的值是"on",否则它的值为"off"。


XQuery Static Flagger status. This component has the value "on" if the XQuery Static Flagger is implemented and enabled; otherwise it has the value "off".
XQuery静态标志器状态(XQuery Static Flagger status)。如果XQuery静态标志器被实现而且启用,这个构件的值是"on",否则,其值为"off"。

2.1.2 Dynamic Context

2.1.2 动态语境

[Definition: The dynamic context of an expression is defined as information that is available at the time the expression is evaluated.] 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, a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) is raised.[err:XP0002 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0002)]
[定义:一个表达式的动态语境是指表达式求值时可用的信息。]如果一个表达式的求值依赖于动态语境 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-context)的某些尚未赋值的部分,就会引发一个动态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error)。[err:XP0002 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0002)]
The individual components of the dynamic context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-context) are summarized below. Further rules governing the semantics of these components can be found in C.2 Dynamic Context Components.
动态语境 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-context)的各构件总结如下。控制这些构件语义的更多规则参见C.2动态语境构件
The dynamic context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-context) consists of all the components of the static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context), and the additional components listed below.
动态语境 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-context)静态语境 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context)的所有构件,外加下面列出的构件组成。
[Definition: 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. ] The focus enables the processor to keep track of which nodes are being processed by the expression.
[定义:动态语境 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-context)的前三个构件(语境项、语境位置和语境大小)称为表达式的焦点(focus)。]焦点使得处理器可以跟踪表达式当前处理的节点。
Certain language constructs, notably the path expression E1/E2 and the filter expression E1[E2], create a new focus for the evaluation of a sub-expression. In these constructs, E2 is evaluated once for each item in the sequence that results from evaluating E1. Each time E2 is evaluated, it is evaluated with a different focus. The focus for evaluating E2 is referred to below as the inner focus, while the focus for evaluating E1 is referred to as the outer focus. The inner focus exists only while E2 is being evaluated. When this evaluation is complete, evaluation of the containing expression continues with its original focus unchanged.
某些语言构造式,尤其是路径表达式(path expression)E1/E2 和过滤表达式(filter expression)E1[E2] ,为一个子表达式的求值创建了一个新的焦点。在这些构造式中,对 E1 求值的结果序列中的每个项,E2都要计算一次。每次 E2 计算时,焦点都不同。在下面,计算 E2 的焦点被称为内焦点(inner focus),计算 E1 的焦点称为外焦点(outer focus)。内焦点只有当 E2 计算时才存在。当该计算结束后,外部包含它的表达式(containing expression)的计算继续而其最初的焦点保持不变。


[Definition: The context item is the item currently being processed. An item is either an atomic value or a node.][Definition: When the context item is a node, it can also be referred to as the context node.] The context item is returned by the expression ".". When an expression E1/E2 or E1[E2] is evaluated, each item in the sequence obtained by evaluating E1 becomes the context item in the inner focus for an evaluation of E2.
[定义:语境项(context item)是当前正在处理的项。一个项是原子值(atomic value)或者一个节点。][定义:当语境项是节点时,它也可以被称为语境节点(context node)。]语境项通过表达式 "." 返回。当计算表达式 E1/E2 或者 E1[E2] 时,计算 E1 得到的序列的每个项成为计算 E2 的内焦点中的语境项。


[Definition: The context position is the position of the context item within the sequence of items currently being processed.] It changes whenever the context item changes. Its value is always an integer greater than zero. The context position is returned by the expression fn:position(). When an expression E1/E2 or E1[E2] is evaluated, the context position in the inner focus for an evaluation of E2 is the position of the context item in the sequence obtained by evaluating E1. The position of the first item in a sequence is always 1 (one). The context position is always less than or equal to the context size.
[定义:语境位置(context position)是语境项在当前正在处理的项的序列中的位置。]语境项一旦改变它就改变。它的值永远是一个大于零的整数。语境位置通过表达式fn:position()返回。当计算表达式E1/E2或者E1[E2]时,计算E2时的内焦点中的语境位置是计算E1得到的序列中语境项的位置。一个序列中的第一个项的位置永远是1,语境位置永远小于或等于语境大小。


[Definition: The context size is the number of items in the sequence of items currently being processed.] Its value is always an integer greater than zero. The context size is returned by the expression fn:last(). When an expression E1/E2 or E1[E2] is evaluated, the context size in the inner focus for an evaluation of E2 is the number of items in the sequence obtained by evaluating E1.
[定义:语境大小(context size)是当前正在被处理的项的序列中项的数目。]它的值永远是一个大于的整数。语境大小通过表达式fn:last()返回。当计算表达式E1/E2或者E1[E2]时,计算E2的内焦点中的语境大小是计算E1得到的序列中项的数目。


[Definition: 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.]
[定义:变量值(Variable values)。它是一个(扩展QName,值)对的集合。它含有与该表达式的静态语境 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context)中的作用域内变量 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-in-scope-variables)相同的扩展QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-expanded-qname)。QName是变量名,值则是变量的动态值。]


[Definition: 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 implementations)。函数签名 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-function-signature)中的每个函数有一个函数实现,它使得函数将其参数类型的实例映射到其结果类型的实例。对于一个用户自定义函数 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-udf),函数实现是一个XQuery表达式。对于一个外部函数 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-external-function),函数实现是依赖于实现 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent)的。


[Definition: 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.]
[定义:当前日期和时间(Current date and time)。该信息表示了处理一个查询或转换的那段时间中一个依赖于实现 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent)的点。它可以被fn:current-date、fn:current-time和fn:current-datetime函数找回(retrieve)。如果在一个查询或者转换的执行过程中激活了多个时间,这些函数永远返回相同的结果。]


[Definition: 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.]
[定义:隐含时区(Implicit timezone)。当一个不含时区的date、time或者dateTime值用于比较或者任何其它操作时,就要用到这个时区。它的值是依赖于实现的 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-defined) xdt:dayTimeDuration 的一个实例。关于一个时区的有效值范围请参看[ISO 8601 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ISO8601)]。


[Definition: 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.] The set of available documents is not constrained by the set of statically known documents (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-known-docs), and it may be empty.
[定义:可用文档(Available documents)。是从字符串到文档节点的一个映射。字符串表示一个资源的绝对URI。文档节点是用数据模型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel)表示资源的一棵树的根节点。当把fn:doc函数应用到该URI时,文档被返回。]可用的文档集不受到静态已知文档 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-known-docs)的限制,而且可能是空的。


[Definition: 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. ] The set of available collections is not constrained by the set of statically known collections (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-known-collections), and it may be empty.
[定义:可用集合(Available collections)。是从字符串到节点序列的一个映射。字符串表示一个资源的绝对URI。节点序列表示当该URI作为参数时fn:collection 函数返回的结果。]可用的集合不受静态已知集合 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-known-collections)的限制,而且可能为空。

2.2 Processing Model

2.2 处理模型

XQuery is defined in terms of the data model (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel) and in terms of the expression context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-expression-context).
XQuery是根据数据模型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel)表达式语境 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-expression-context)定义的。 ProcMod-XQuery.gif
Figure 1: Processing Model Overview
图1:处理模型概貌
Figure 1 provides a schematic overview of the processing steps that are discussed in detail below. Some of these steps are completely outside the domain of XQuery; in Figure 1, these are depicted outside the line that represents the boundaries of the language, an area labeled the external processing domain. The external processing domain includes generation of the data model (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel) (see 2.2.1 Data Model Generation), schema import processing (see 2.2.2 Schema Import Processing) and serialization (see 2.2.4 Serialization). The area inside the boundaries of the language is known as the query processing domain, which includes the static analysis and dynamic evaluation phases (see 2.2.3 Expression Processing). Consistency constraints on the query processing domain are defined in 2.2.5 Consistency Constraints.
图1给出了处理步骤的一个概述,这些步骤的细节在下文中讨论。这些步骤中有些是完全在XQuery范围之外的;在图1中,它们用标记了外部处理范围的区域表示,画在表示语言边界的线之外。外部处理范围包括数据模型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel)的产生(见2.2.1数据模型产生),模式导入处理(见2.2.2 模式导入处理)和序列化(见2.2.4 序列化)。语言边界以内的区域被称为查询处理范围,它包括静态分析和动态计算阶段(见2.2.3表达式处理)。查询处理范围上的一致性约束在2.2.5 一致性约束中定义。

2.2.1 Data Model Generation

2.2.1 数据模型产生

Before an expression can be processed, the input documents to be accessed by the expression must be represented in the data model (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel). This process occurs outside the domain of XQuery, which is why Figure 1 represents it in the external processing domain. Here are some steps by which an XML document might be converted to the data model (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel):
在一个表达式处理之前,表达式要访问的输入文档必须用数据模型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel)表示。这个过程发生在XQuery范围之外,这就是为什么图1把它表示在外部处理范围里。一个XML文档转换成为数据模型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel)可能要经过这样几步:


A document may be parsed using an XML parser that generates an XML Information Set (see [XML Infoset (http://www.w3.org/TR/2004/WD-xquery-20040723/#XINFO)]). The parsed document may then be validated against one or more schemas. This process, which is described in [XML Schema (http://www.w3.org/TR/2004/WD-xquery-20040723/#XMLSchema)], results in an abstract information structure called the Post-Schema Validation Infoset (PSVI). If a document has no associated schema, its Information Set is preserved. (See DM1 in Fig. 1.)
一个文档用一个XML解析器进行解析,产生XML信息集(见 [XML Infoset (http://www.w3.org/TR/2004/WD-xquery-20040723/#XINFO)])。然后可能针对一个或多个模式对解析后的文档进行验证。这个过程在[XML Schema (http://www.w3.org/TR/2004/WD-xquery-20040723/#XMLSchema)]中描述,其结果是一个抽象的信息结构称为后模式验证信息集(Post-Schema Validation Infoset, PSVI)。如果一个模式没有相关联的模式,它的信息集就被保留下来。(见图1种的DM1)


The Information Set or PSVI may be transformed into the data model (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel) by a process described in [XQuery 1.0 and XPath 2.0 Data Model (http://www.w3.org/TR/2004/WD-xquery-20040723/#datamodel)]. (See DM2 in Fig. 1.)
信息集或者PSVI可能被转换到数据模型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel),这个过程在[XQuery 1.0 and XPath 2.0 Data Model (http://www.w3.org/TR/2004/WD-xquery-20040723/#datamodel)]中有描述。(见图1的DM2)
The above steps provide an example of how a document in the data model (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel) might be constructed. A document or fragment might also be synthesized directly from a relational database, or constructed in some other way (see DM3 in Fig. 1.) XQuery is defined in terms of operations on the data model (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel), but it does not place any constraints on how documents and instances in the data model (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel) are constructed.
上面的步骤给出了一个数据模型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel)中的文档如何创建的例子。一个文档或者片断也可能直接从关系数据库生成,或者以其他方式创建(见图1的DM3)。XQuery是用数据模型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel)中的操作定义的,但是它并不对文档和数据模型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel)的实例如何产生施加约束。
Each atomic value, element node, and attribute node in the data model (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel) is annotated with its dynamic type (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-type). The dynamic type specifies a range of values—for example, an attribute named version might have the dynamic type xs:decimal, indicating that it contains a decimal value. For example, if the data model (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel) was derived from an input XML document, the dynamic types of the elements and attributes are derived from schema validation.
数据模型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel)中的每个原子值、元素节点和属性节点都带有它的动态类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-type)作注解。动态类型指定了一序列的值——比如,一个名为version的属性可能有动态类型xs:decimal,表示它包含了一个小数值。比如,如果数据模型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel)是从一个输入的XML文档派生而来的,元素和属性的动态类型就是从模式验证派生而来。
The value of an attribute is represented directly within the attribute node. An attribute node whose type is unknown (such as might occur in a schemaless document) is annotated with the dynamic type xdt:untypedAtomic.
属性的值直接在属性节点中表示。一个属性节点如果其类型未知(如无模式文档中出现的情况),就用动态类型xdt:untypedAtomic作注解。
The value of an element is represented by the children of the element node, which may include text nodes and other element nodes. The dynamic type of an element node indicates how the values in its child text nodes are to be interpreted. An element that has not been validated (such as might occur in a schemaless document) is annotated with the type xdt:untyped. An element that has been validated and found to be partially valid is annotated with the type xs:anyType. If an element node is annotated xdt:untyped, all its descendant element nodes are also annotated xdt:untyped. However, if an element node is annotated xs:anyType, some of its descendant element nodes may have a more specific type annotation.
一个元素的值是用元素节点的孩子表示的,包括文本节点和其它元素节点。一个元素节点的动态类型指出了它的子文本节点中的值如何理解。没有验证(如无模式文档中出现的情况)的元素用类型xdt:untyped作注解。如果一个元素已经经过验证而且部分有效,则用类型xs:anyType作注解。如果一个元素节点xdt:untyped用注解,它所有的后裔元素节点也用xdt:untyped注解。然而,如果一个元素节点用xs:anyType注解,它的某些后裔元素节点可能会有一个更具体的类型注解。
An atomic value of unknown type is annotated with the type xdt:untypedAtomic.
一个不知其类型的原子值用类型xdt:untypedAtomic注解。

2.2.2 Schema Import Processing

2.2.2 模式导入处理

The in-scope schema definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd) in the static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context) may be extracted from actual XML Schemata as described in [XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)] (see step SI1 in Figure 1) or may be generated by some other mechanism (see step SI2 in Figure 1). In either case, the result must satisfy the consistency constraints defined in 2.2.5 Consistency Constraints.
静态语境 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context)中的作用域内模式定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd)可以从实际的XML模式中抽取,就像[XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)](见图1中的SI1)中描述的那样,也可以通过其它机制产生(见图1的SI2)。无论哪种情况,结果都必须满足2.2.5一致性约束中定义的一致性约束。

2.2.3 Expression Processing

2.2.3 表达式处理

XQuery defines two phases of processing called the static analysis phase (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis) and the dynamic evaluation phase (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-evaluation) (see Fig. 1). An implementation is free to use any strategy or algorithm whose result conforms to these specifications.
XQuery定义了两个阶段的处理称为静态分析阶段 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis)动态计算阶段 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-evaluation)(见图1)。实现可以自由使用任何策略或算法,只要其结果遵从这些规范。

2.2.3.1 Static Analysis Phase
2.2.3.1 静态分析阶段



[Definition: 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).]
[定义:静态分析阶段依赖于表达式本身和静态语境 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context)静态分析阶段不依赖于输入数据(其它模式)]
During the static analysis phase, the query is parsed into an internal representation called the operation tree (step SQ1 in Figure 1). A parse error is raised as a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error).[err:XP0003 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0003)] The static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context) is initialized by the implementation (step SQ2). The static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context) is then changed and augmented based on information in the prolog (step SQ3). If the Schema Import Feature (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-schema-import-feature) is supported, the in-scope schema definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd) are populated with information from imported schemata. The static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context) is used to resolve type names, function names, namespace prefixes and variable names (step SQ4). If a name in the operation tree is not found in the static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context), a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) [err:XP0008 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0008)] is raised (however, see exceptions to this rule in 2.4.4.3 Element Test and 2.4.4.5 Attribute Test.
在静态分析阶段,查询被解析成一种称为操作树的内部表示(图1中步骤SQ1)。解析错误会当作静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)引发。[err:XP0003 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0003)]静态语境 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context)由实现初始化。然后根据序中的信息改变和增强静态语境 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context)(步骤SQ3)。如果支持模式导入特征 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-schema-import-feature)作用域内模式定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd)中就会加入导入模式的信息。静态语境 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context)被用来解析类型名、函数名、命名空间前缀和变量名(步骤SQ4)。如果操作树中的某个名字不在静态语境 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context)中,就会引发一个静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)[err:XP0008 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0008)](这个规则的例外参见2.4.4.3元素测试2.4.4.5属性测试
The operation tree is then normalized by making explicit the implicit operations such as atomization (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-atomization), type promotion (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-promotion), and extraction of Effective Boolean Values (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-ebv) (step SQ5). The normalization process is described in [XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)].
操作树然后被规范化(normalized ),即将隐式操作如原子化 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-atomization)类型提升 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-promotion)(type promotion)和有效布尔值 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-ebv)(Effective Boolean Values)的抽取等(见步骤SQ5)显式化。规范化步骤在[XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)]中有描述。
If the Static Typing Feature (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-typing-feature) is supported, each expression is assigned a static type (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type) (step SQ6). [Definition: 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)].] In some cases, the static type (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type) is derived from the lexical form of the expression; for example, the static type (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type) of the literal 5 is xs:integer. In other cases, the static type (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type) of an expression is inferred according to rules based on the static types of its operands; for example, the static type (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type) of the expression 5 + 1.2 is xs:decimal.
如果支持静态类型特征 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-typing-feature)的话,每个表达式都被赋予一个静态类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type)(步骤SQ6)。[定义:一个表达式的静态类型可能是一个有名类型或者一段结构化描述——例如,xs:boolean?表示xs:boolean类型的出现是可选的。推导各种表达式的静态类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type)的规则在[XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)]中有描述。]有些情况下静态类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type)是从表达式的词法结构中衍生的;例如,字符5的静态类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type)是xs:integer。其它情形下,一个表达式的静态类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type)是根据基于操作数的静态类型的规则推导出来的;例如,表达式5 + 1.2 的静态类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type)是xs:decimal。
During the static analysis phase (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis), if the Static Typing Feature (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-typing-feature) is in effect and an operand of an expression is found to have a static type (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type) that is not appropriate for that operand, a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) is raised.[err:XP0004 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0004)] If static type checking raises no errors and assigns a static type (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type) T to an expression, then execution of the expression on valid input data is guaranteed either to produce a value of type T or to raise a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error).
静态分析阶段 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis),如果静态类型特征 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-typing-feature)起作用,而且一个表达式的一个操作数的静态类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type)与该操作数不相称的话,就会引起一个类型错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error)。[err:XP0004 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0004)]如果静态类型检查没有引发错误,并且给一个表达式赋静态类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type)T,该表达式在有效输入数据上的执行可以保证要么产生一个类型T的值,要么引发一个动态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error)
During the static analysis phase (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis), if the Static Typing Feature (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-typing-feature) is in effect and the static type (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type) assigned to an expression other than () or data(()) is empty(), a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) is raised.[err:XP0005 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0005)] This catches cases in which a query refers to an element or attribute that is not present in the in-scope schema definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd), possibly because of a spelling error.
静态分析阶段 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis),如果静态类型特征 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-typing-feature)起作用,并且一个()和data()之外的表达式的静态类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type)是empty(),就会引发一个静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)。[err:XP0005 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0005)]这反映了这样的情形,即查询引用了一个作用域内模式定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd)中没有的元素或属性,这种情形通常是因为拼写错误引起的。
The purpose of type-checking during the static analysis phase (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis) is to provide early detection of type errors (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) and to infer type information that may be useful in optimizing the evaluation of an expression.
静态分析阶段 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis)类型检查的目的是为了及早发现类型错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error),并且推导出可能有助于优化一个表达式的计算的类型信息。

2.2.3.2 Dynamic Evaluation Phase
2.2.3.2 动态计算阶段



[Definition: 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.]
[定义:动态计算阶段出现在静态分析阶段 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis)之后。在动态计算阶段里,查询的值被计算。]
The dynamic evaluation phase can occur only if no errors were detected during the static analysis phase (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis). If the Static Typing Feature (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-typing-feature) is in effect, all type errors (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) are detected during static analysis and serve to inhibit the dynamic evaluation phase. If the Static Typing Feature (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-typing-feature) is not in effect, an implementation is allowed to raise type-related warnings during the static analysis phase (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis). It may then proceed with the dynamic evaluation phase; in this case, type errors (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) must be detected and raised during dynamic evaluation.
只有当静态分析阶段 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis)没有发现错误时,动态计算阶段才会出现。如果静态类型特征 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-typing-feature)起作用的话,所有类型错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error)在静态分析时就被检测出来,这些错误导致动态计算阶段不再出现。如果静态类型特征 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-typing-feature)不起作用的话,实现可以在静态分析阶段 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis)引发与类型有关的警告。然后可能继续到动态计算阶段;此时,类型错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error)必须在动态计算时发现和引发。
The dynamic evaluation phase depends on the operation tree of the expression being evaluated (step DQ1), on the input data (step DQ4), and on the dynamic context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-context) (step DQ5), which in turn draws information from the external environment (step DQ3) and the static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context) (step DQ2). Execution of the evaluation phase may create new data-model values (step DQ4) and it may extend the dynamic context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-context) (step DQ5)—for example, by binding values to variables.
动态计算阶段依赖于正在计算的表达式的操作树(步骤DQ1),输入数据(步骤DQ4)和动态语境 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-context)(步骤DQ5),而动态语境又最终从外部环境(步骤DQ3)和静态语境 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context)(步骤DQ2)中获取信息。计算阶段的执行可能会产生新的数据模型值(步骤DQ4),也可能扩充动态语境 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-context)(步骤DQ5)——例如,将值绑定到变量。
[Definition: 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.] The dynamic type of a value may be more specific than the static type (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type) of the expression that computed it (for example, the static type (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type) of an expression might be "zero or more integers or strings," but at evaluation time its value may have the dynamic type "integer.")
[定义:当每个值计算时都与一个动态类型关联。一个值的动态类型或者是一段结构化描述(例如“整数序列”)或者是一个有名类型。]一个值的动态类型可能比计算它的表达式的静态类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type)更具体(比如,一个表达式的静态类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type)可能是“零个或多个整数或字符串,”但是在计算时,它的值可能有动态类型“整数。”)
If an operand of an expression is found to have a dynamic type (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-type) that is not appropriate for that operand, a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) is raised.[err:XP0006 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0006)]
如果一个表达式的操作数有与之不相称的动态类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-type),就会引发一个类型错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error)。[err:XP0006 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0006)]
Even though static typing can catch many type errors (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) before an expression is executed, it is possible for an expression to raise an error during evaluation that was not detected by static analysis. For example, an expression may contain a cast of a string into an integer, which is statically valid. However, if the actual value of the string at run time cannot be cast into an integer, a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) will result. Similarly, an expression may apply an arithmetic operator to a value whose static type (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type) is xdt:untypedAtomic. This is not a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error), but at run time, if the value cannot be successfully cast to a numeric type, a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) will be raised.
即使静态类型特征可以在一个表达式执行之前捕捉很多类型错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error),一个表达式仍然有可能在计算阶段引发一个被静态分析没有检测到的错误。例如,一个表达式可能包含一个字符串到一个整数的转换,在静态下这是有效的。但是,如果运行时该字符串的实际值不能转换成为一个整数,就会导致一个动态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error)。类似地,一个表达式可能将算术操作符作用到静态类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type)为xdt:untypedAtomic的一个值上。这不是一个静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error),但在运行时,如果该值不能顺利地转换为数值类型,就会引发一个动态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error)
When the Static Typing Feature (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-typing-feature) is in effect, it is also possible for static analysis of an expression to raise a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error), even though execution of the expression on certain inputs would be successful. For example, an expression might contain a function that requires an element as its parameter, and the static analysis phase might infer the static type (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type) of the function parameter to be an optional element. This case is treated as a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) and inhibits evaluation, even though the function call would have been successful for input data in which the optional element is present.
静态类型特征 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-typing-feature)起作用时,也可能一个表达式静态分析会引发一个类型错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error),即使该表达式在某些输入上可能成功执行。例如,一个表达式可能含有一个函数,而该函数要求一个元素作为它的参数,静态分析阶段可能认为,该函数参数的静态类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type)是一个可选的元素。这种情形被视作一个类型错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error),而且导致计算无法进行,尽管对那些存在可选的元素的输入数据,该函数调用能够顺利执行。

2.2.4 Serialization

2.2.4 序列化

[Definition: 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.) ] The general framework for serialization of the data model (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel) is described in [XSLT 2.0 and XQuery 1.0 Serialization (http://www.w3.org/TR/2004/WD-xquery-20040723/#serialization)].
[定义:序列化是将数据模型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel)的节点和原子值序列转换为八位组序列的过程(图1步骤DM4。)]数据模型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel)序列化的一般框架在[XSLT 2.0 and XQuery 1.0 Serialization (http://www.w3.org/TR/2004/WD-xquery-20040723/#serialization)]中有描述。
An XQuery implementation is not required to provide a serialization interface. For example, an implementation may only provide a DOM interface or an interface based on an event stream. In these cases, serialization would be outside of the scope of this specification.
一个XQuery的实现不要求提供序列化接口。比如,一个实现可能仅仅只提供一个DOM接口或者基于事件流的接口。在这些情形下,序列化可能在本规范的范围之外。
[XSLT 2.0 and XQuery 1.0 Serialization (http://www.w3.org/TR/2004/WD-xquery-20040723/#serialization)] defines a set of serialization parameters that govern the serialization process. If an XQuery implementation provides a serialization interface, it may support (and may expose to users) any of the serialization parameters listed (with default values) in C.3 Serialization Parameters. An XQuery implementation that provides a serialization interface must support some combination of serialization parameters in which method = "xml" and version = "1.0".
[XSLT 2.0 and XQuery 1.0 Serialization (http://www.w3.org/TR/2004/WD-xquery-20040723/#serialization)]定义了一个控制序列化进程的序列化参数集。如果一个XQuery实现提供了一个序列化接口,它可能支持(也可能让用户知道)C.3序列化参数列出的(带缺省值的)任何序列化参数。一个提供了序列化接口的XQuery的实现必须支持某些序列化参数的组合,其中method = "xml" 而且version = "1.0" 。

2.2.5 Consistency Constraints

2.2.5 一致性约束

In order for XQuery to be well defined, the data model (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel), the static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context), and the dynamic context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-context) must be mutually consistent. The consistency constraints listed below are prerequisites for correct functioning of an XQuery implementation. Enforcement of these consistency constraints is beyond the scope of this specification. This specification does not define the result of a query under any condition in which one or more of these constraints is not satisfied.
为了使得XQuery是定义良好的,数据模型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel)静态语境 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context)动态语境 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-context)必须相互一致。下面列出的一致性约束是一个XQuery实现正确工作的先决条件。
Some of the consistency constraints use the term data model schema. [Definition: 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.] For a node that was constructed by some process other than schema validation, the data model schema consists simply of the type definition that is represented by the type annotation of the node.
有些一致性约束使用了术语数据模型模式。[定义:对于数据模型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel)中的给定节点,该节点的类型注解从一定的模式衍生而来,这个模式就是数据模型模式。]对于一个通过其它途径而不是模式验证构造的节点,数据模型模式只由该节点的类型注解所表示的类型定义组成。


For every data model node that has a type annotation, if that type annotation is found in the in-scope schema definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd) (ISSD), then its definition in the ISSD must be the same as its definition in the data model schema (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-data-model-schema). Furthermore, all types that are derived by extension from the given type in the data model schema (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-data-model-schema) must also be known by equivalent definitions in the ISSD.

 对于每个有类型注解的数据模型来说,如果该类型注解在作用域内模式定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd)(ISSD)中,则它在ISSD中的定义就必须和它在数据模型模式 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-data-model-schema)中的定义相同。更进一步地,对数据模型模式 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-data-model-schema)中的给定类型扩充而得到的所有类型也必须为ISSD中的对等定义所了解。

For every element name EN that is found both in a data model node and in the in-scope schema definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd) (ISSD), all elements that are known in the data model schema (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-data-model-schema) to be in the substitution group (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-substitution-group) headed by EN must also be known in the ISSD to be in the substitution group (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-substitution-group) headed by EN.
对每个同时在数据模型节点和作用域内模式定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd)(ISSD)中出现的元素名EN,在数据模型模式 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-data-model-schema)中已知的出现在EN开头的置换组 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-substitution-group)中的所有元素必须也是ISSD中已知的出现在EN开头的置换组 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-substitution-group)中。


Every item type (i.e., every element, attribute, or type name) referenced in in-scope variables (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-in-scope-variables) or function signatures (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-function-signature) must be in the in-scope schema definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd).
作用域内变量 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-in-scope-variables)或者函数签名 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-function-signature)引用的每个项类型(即每个元素、属性或类型名)必须在作用域内模式定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd)(ISSD)中。


For each mapping of a string to a document node in available documents (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-available-docs), if there exists a mapping of the same string to a document type in statically known documents (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-known-docs), the document node must match the document type, using the matching rules in 2.4.4 SequenceType Matching.
对每个从字符串到可用文档 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-available-docs)中的一个文档节点的映射,如果存在从相同字符串到静态已知文档 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-known-docs)中的一个文档类型的映射,根据2.4.4序列类型匹配中的匹配规则,该文档节点必须与该文档类型匹配。


For each mapping of a string to a sequence of nodes in available collections (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-available-collections), if there exists a mapping of the same string to a type in statically known collections (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-known-collections), the sequence of nodes must match the type, using the matching rules in 2.4.4 SequenceType Matching.
对每个从字符串到可用集合 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-available-collections)中的一个节点序列的映射,如果存在从相同字符串到静态已知集合 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-known-collections)中的一个类型的映射,根据2.4.4序列类型匹配中的匹配规则,该节点序列必须与该类型匹配。


For each (variable, type) pair in in-scope variables (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-in-scope-variables) and the corresponding (variable, value) pair in variable values (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-variable-values) such that the variable names are equal, the value must match the type, using the matching rules in 2.4.4 SequenceType Matching.
作用域内变量 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-in-scope-variables)的每个(变量,类型)对,变量值 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-variable-values)中变量名与之相等的相应的每个(变量,值)对,根据2.4.4 序列类型匹配中的匹配规则,该值必须与该类型匹配。


For each variable declared as external: If the variable declaration includes a declared type, the external environment must provide a value for the variable that matches the declared type, using the matching rules in 2.4.4 SequenceType Matching. If the variable declaration does not include a declared type, the external environment must provide a type and a matching value, using the same matching rules.
对每个声明为external:的变量:如果变量的声明中包含了一个已声明的类型,根据2.4.4 序列类型匹配中的匹配规则,外部环境中必须有该变量的一个值与该类型匹配。如果变量声明不包含一个已声明的类型,根据相同的匹配规则,外部环境必须提供一个类型和一个匹配的值。


For a given query, define a participating ISSD as the in-scope schema definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd) of a module that is used in evaluating the query. If two participating ISSDs contain a definition for the same type name, element name, or attribute name, the definitions must be equivalent in both ISSDs. Furthermore, if two participating ISSDs each contain a definition of a type name T, the set of types derived by extension from T must be equivalent in both ISSDs. Also, if two participating ISSDs each contain a definition of an element name E, the substitution group headed by E must be equivalent in both ISSDs.
对于一个给定查询,将一个参与ISSD(participating ISSD)定义为查询计算中用到的一个模块的作用域内模式定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd)。如果两个参与ISSD包含了相同类型名、元素名或者属性名的定义,那么两个ISSD中的定义必须等价。更进一步地,如果两个参与ISSD每个都包含了一个类型名T的定义,对T扩展而得来的两个ISSD中的类型必须是等价的。而且,如果两个参与ISSD每个包含了元素名E的一个定义,以E开头的置换组在两个ISSD中必须是等价的。

2.3 Documents

2.3 文档

XQuery is generally used to process documents. The representation of a document is normatively defined in [XQuery 1.0 and XPath 2.0 Data Model (http://www.w3.org/TR/2004/WD-xquery-20040723/#datamodel)]. The functions used to access documents and collections are normatively defined in [XQuery 1.0 and XPath 2.0 Functions and Operators (http://www.w3.org/TR/2004/WD-xquery-20040723/#FunctionsAndOperators)]. Because documents are centrally important in XQuery processing, we provide a summary of some key concepts here.
XQuery通常用来处理文档。文档的表示在 [XQuery 1.0 and XPath 2.0 Data Model (http://www.w3.org/TR/2004/WD-xquery-20040723/#datamodel)]中规范地定义了。访问文档和集合的函数在[XQuery 1.0 and XPath 2.0 Functions and Operators (http://www.w3.org/TR/2004/WD-xquery-20040723/#FunctionsAndOperators)]中规范地定义了。因为文档在XQuery处理中是重中之重,我们将一些关键概念总结如下。

2.3.1 Document Order

2.3.1 文档顺序

An ordering called document order is defined among all the nodes used during a given query or transformation, which may consist of one or more trees (documents or fragments). Document order is defined in [XQuery 1.0 and XPath 2.0 Data Model (http://www.w3.org/TR/2004/WD-xquery-20040723/#datamodel)], and its definition is repeated here for convenience. [Definition: The node ordering that is the reverse of document order is called reverse document order.]
一个给定查询或者转换用到的所有节点中定义了一个称为文档顺序的顺序,这些节点可能有一个或多个(文档或片断)组成。文档顺序在 [XQuery 1.0 and XPath 2.0 Data Model (http://www.w3.org/TR/2004/WD-xquery-20040723/#datamodel)] 中被定义,为了方便,这里再次重复它的定义。[定义:如果节点次序是文档顺序的逆序,则称为逆文档顺序。]
Document order is a total ordering, although the relative order of some nodes is implementation-dependent (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent). [Definition: Informally, document order is the order defined by a pre-order, depth-first traversal of the nodes in the data model.] Document order is stable, which means that the relative order of two nodes will not change during the processing of a given query or transformation, even if this order is implementation-dependent (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent).
文档顺序是一个全序,尽管某些节点的相对顺序是依赖于实现 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent)的。[定义:非正式的说,文档顺序是对数据模型中的节点按先序、深度优先遍历确定的顺序。]文档顺序是稳定的,意思是两个节点的相对顺序在给定查询或者转换处理过程中不会改变,尽管该顺序是依赖于实现 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent)的。
Within a tree, document order satisfies the following constraints:
在树中,文档顺序满足如下约束:


The root node is the first node.
根节点是第一个节点。


The relative order of siblings is determined by their order in the XML representation of the tree. A node N1 occurs before a node N2 in document order if and only if the start of N1 occurs before the start of N2 in the XML representation.
兄弟节点的相对顺序由它们在树的XML表示中的顺序决定。节点N1按文档顺序在N2之前当且仅当在XML表示中N1的开始在N2的开始之前。


Attribute nodes immediately follow the element node with which they are associated. The relative order of attribute nodes is stable but implementation-dependent (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent).
属性节点紧接着它们关联的元素节点。属性节点间的相对顺序是稳定的但是依赖于实现 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent)的。


Element nodes occur before their children; children occur before following-siblings.
元素节点在它们的孩子之前;孩子在后兄弟之前。
The relative order of nodes in distinct trees is stable but implementation-dependent (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent), subject to the following constraint: If any node in tree T1 is before any node in tree T2, then all nodes in tree T1 are before all nodes in tree T2.
不同树中的节点之间的相对顺序是稳定的但是依赖于实现 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent)的,并且受如下约束:如果树T1的任意节点在T2的任意节点之前,那么树T1的所有节点在树T2的所有节点之前。

2.3.2 Atomization

2.3.2 原子化

The semantics of some XQuery operators depend on a process called atomization (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-atomization). [Definition: 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)].]
某些XQuery操作符的语义依赖于一个称为原子化 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-atomization)的过程。[定义:当一个值用在一个需要原子值序列的语境中时,原子化被作用到该值上。原子化的结果是一个原子值的序列或者一个类型错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error)。一个序列的原子化定义为在该序列上调用 fn:data 函数时的结果,如同在 [XQuery 1.0 and XPath 2.0 Functions and Operators (http://www.w3.org/TR/2004/WD-xquery-20040723/#FunctionsAndOperators)]定义的那样。]
The semantics of fn:data are repeated here for convenience. The result of fn:data is the sequence of atomic values produced by applying the following rules to each item in the input sequence:
为了方便,fn:data 的语义在这里再次给出。fn:data 的结果是把如下的规则应用到输入序列中的每个项产生的原子值的序列:


If the item is an atomic value, it is returned.
如果该项是原子值,则返回。


If the item is a node, its typed value is returned.
如果该项是一个节点,则其类型值返回。
Atomization is used in processing the following types of expressions:
原子化用于处理如下类型的表达式:


Arithmetic expressions
算术表达式


Comparison expressions
比较表达式


Function calls and returns
函数调用和返回


Cast expressions
转换表达式


Computed element and attribute constructors.
计算式元素和属性构造器

2.3.3 Effective Boolean Value

2.3.3 有效布尔值

Under certain circumstances (listed below), it is necessary to find the effective boolean value (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-ebv) of a value. [Definition: 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)].]
在某些情况下(如下列出),需要找出一个值的有效布尔值 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-ebv)。[定义:一个值的有效布尔值定义为将fn:boolean函数作用到该值时的结果,如同[XQuery 1.0 and XPath 2.0 Functions and Operators (http://www.w3.org/TR/2004/WD-xquery-20040723/#FunctionsAndOperators)] 中定义的那样。]
The semantics of fn:boolean are repeated here for convenience. fn:boolean returns false if its operand is any of the following:
为了方便,fn:data的语义在这里再次给出。如果fn:boolean的操作数是如下任意一种则返回false:


An empty sequence
一个空序列


The boolean value false
布尔值false


A zero-length value of type xs:string or xdt:untypedAtomic

 xs:string或者xdt:untypedAtomic类型的长度为零的值

A numeric value that is equal to zero
等于零的数值型值


The xs:double or xs:float value NaN
xs:double或者xs:float值NaN
Otherwise, fn:boolean returns true.
否则,fn:boolean返回true。
The effective boolean value (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-ebv) of a sequence is computed implicitly during processing of the following types of expressions:
当处理如下类型的表达式时一个序列的有效布尔值被隐式的计算:


Logical expressions (and, or)
逻辑表达式(and,or)


The fn:not function
fn:not函数


The where clause of a FLWOR expression

 FLWOR表达式的where子句

Certain types of predicates, such as a[b]
某些类型的谓词,如a[b]


Conditional expressions (if)
条件表达式(if)


Quantified expressions (some, every)
限定表达式(some,every)
Note:
注意
Note that the definition of effective boolean value (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-ebv) is not used when casting a value to the type xs:boolean.
注意当将一个值转换到xs:boolean类型时没有用到有效布尔值 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-ebv)的概念。

2.3.4 Input Sources

2.3.4 输入源

XQuery has a set of functions that provide access to input data. These functions are of particular importance because they provide a way in which an expression can reference a document or a collection of documents. The input functions are described informally here; they are defined in [XQuery 1.0 and XPath 2.0 Functions and Operators (http://www.w3.org/TR/2004/WD-xquery-20040723/#FunctionsAndOperators)].
XQuery有一组函数提供对输入数据的访问。这些函数特别重要,因为它们提供了一个表达式引用一个文档或文档集的一种方法。这里对输入函数进行非正式地描述,它们在[XQuery 1.0 and XPath 2.0 Functions and Operators (http://www.w3.org/TR/2004/WD-xquery-20040723/#FunctionsAndOperators)]中被定义。
An expression can access input data either by calling one of the input functions or by referencing some part of the expression context that is initialized by the external environment, such as a variable or a context item (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-context-item).
一个表达式通过两种方式访问输入数据:调用这些输入函数中的一个,或者引用外部环境初始化的表达式语境的某一部分,如一个变量或一个语境项 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-context-item)
The input functions supported by XQuery are as follows:
XQuery支持的输入函数有:


The fn:doc function takes a string containing a URI that refers to an XML document, and returns a document node whose content is the data model (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel) representation of the given document.
fn:doc函数接受一个包含URI的字符串,该URI引用一个XML文档,函数返回一个文档节点,其内容是给定文档的数据模型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel)表示。


The fn:collection function takes a string containing a URI, and returns the data model representation of the collection identified by the URI. A collection may be any sequence of nodes. For example, the expression fn:collection("http://example.org")//customer identifies all the customer elements that are descendants of nodes found in the collection whose URI is http://example.org.
fn:collection函数接受一个包含URI的字符串,返回该URI标识的集合的数据模型表示。一个集合可能是任意节点序列。例如,表达式fn:collection("http://example.org")//customer标识URI为http://example.org的集合内节点的后裔中所有customer元素。
If a given input function is invoked repeatedly with arguments that resolve to the same absolute URI during the scope of a single query or transformation, each invocation returns the same result.
如果在单个查询或转换范围内一个给定输入函数被重复调用,而且参数解析到相同的绝对URI,那么每个调用都返回相同的结果。

2.4 Types

XQuery is a strongly typed language with a type system based on [XML Schema (http://www.w3.org/TR/2004/WD-xquery-20040723/#XMLSchema)]. The XQuery type system is formally defined in [XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)].
XQuery是一个强类型语言,它有一个基于[XML Schema (http://www.w3.org/TR/2004/WD-xquery-20040723/#XMLSchema)]的类型系统。XQuery的类型系统在[XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)]中被正式定义。

2.4.1 Predefined Types

2.4.1 预定义类型

The in-scope type definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-types) in the static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context) are initialized with certain predefined types, including the built-in types of [XML Schema (http://www.w3.org/TR/2004/WD-xquery-20040723/#XMLSchema)]. These built-in types are in the namespace http://www.w3.org/2001/XMLSchema, which has the predefined namespace prefix xs. Some examples of built-in schema types include xs:integer, xs:string, and xs:date. Element and attribute declarations in the xs namespace are not implicitly included in the static context.
静态语境 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context)中的作用域内类型定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-types)用某些预定义类型初始化,包括 [XML Schema (http://www.w3.org/TR/2004/WD-xquery-20040723/#XMLSchema)] 的内置类型。这些内置类型在命名空间http://www.w3.org/2001/XMLSchema中,有着预定义的命名空间前缀xs。一些内置的模式类型包括xs:integer,xs:string和xs:data。在xs命名空间中的元素和属性声明并没有隐式地包含在静态语境中。
In addition, the predefined types of XQuery include the types defined in the namespace http://www.w3.org/2004/07/xpath-datatypes, which has the predefined namespace prefix xdt. The types in this namespace are defined in [XQuery 1.0 and XPath 2.0 Functions and Operators (http://www.w3.org/TR/2004/WD-xquery-20040723/#FunctionsAndOperators)] and are summarized below.
此外,XQuery的预定义类型包括在命名空间http://www.w3.org/2004/07/xpath-datatypes中定义的类型,它们有着预定义的命名空间前缀xdt。这个命名空间中的类型在[XQuery 1.0 and XPath 2.0 Functions and Operators (http://www.w3.org/TR/2004/WD-xquery-20040723/#FunctionsAndOperators)]中定义,并总结如下。


[Definition: 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.] It has no subtypes.
[定义:xdt:untyped表示一个没有经过验证或在略过方式下验证的元素节点的动态类型。]它没有子类型。


[Definition: xdt:untypedAtomic is used to denote untyped atomic data, such as text that has not been assigned a more specific type.] It has no subtypes. An attribute that has been validated in skip mode, or that has a PSVI property of xs:anySimpleType, is represented in the Data Model by an attribute node with the type xdt:untypedAtomic.
[定义:xdt:untypedAtomic表示无类型的原子数据,如没有赋予更具体类型的文本。]它没有子类型。一个在略过方式下验证的属性,或者有一个PSVI属性(property)为xs:anySimpleType的属性,在数据模型中用一个xdt:untypedAtomic类型的属性节点表示。


[Definition: xdt:dayTimeDuration is a subtype of xs:duration whose lexical representation is restricted to contain only day, hour, minute, and second components.]
[定义:xdt:dayTimeDuration是xs:duration的子类型,它的词法表示只限于包含day,hour,minute和second等成分。]


[Definition: xdt:yearMonthDuration is a subtype of xs:duration whose lexical representation is restricted to contain only year and month components.]
[定义:xdt:yearMonthDuration是xs:duration的子类型,它的词法表示只限于包含year和month等成分。]


[Definition: xdt:anyAtomicType includes all atomic values (and no values that are not atomic).] It is a subtype of xs:anySimpleType, which is the base type for all simple types, including atomic, list, and union types. All specific atomic types such as xs:integer, xs:string, and xdt:untypedAtomic, are subtypes of xdt:anyAtomicType.
[定义:xdt:anyAtomicType包括所有原子值(没有值不是原子的)。]它是xs:anySimpleType的子类型,xs:anySimpleType是所有简单类型的基类型,包括原子类型、列表类型和联合类型。所有具体的原子类型如xs:integer、xs:string和xdt:untypedAtomic都是xdt:anyAtomicType的子类型。
Note:
注意:
xdt:anyAtomicType will not appear as the type of an actual value in the Data Model.
xdt:anyAtomicType在数据模型中不会作为实际值的类型出现。
The relationships among the types in the xs and xdt namespaces are illustrated in Figure 2. A more complete description of the XQuery type hierarchy can be found in [XQuery 1.0 and XPath 2.0 Functions and Operators (http://www.w3.org/TR/2004/WD-xquery-20040723/#FunctionsAndOperators)].
xs 和xdt 命名空间中的类型之间的关系如图2所示。XQuery类型层次的更完整的描述可以在[XQuery 1.0 and XPath 2.0 Functions and Operators (http://www.w3.org/TR/2004/WD-xquery-20040723/#FunctionsAndOperators)]找到。
types.jpg
Figure 2: Summary of XQuery Type Hierarchy
图2:XQuery类型层次图概况

2.4.2 Typed Value and String Value

2.4.2 类型值和字符串值

In the data model (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel), every node has a typed value and a string value. The typed value of a node is a sequence of atomic values and can be extracted by applying the fn:data function to the node. The typed value for each kind of node is defined by the dm:typed-value accessor in [XQuery 1.0 and XPath 2.0 Data Model (http://www.w3.org/TR/2004/WD-xquery-20040723/#datamodel)]. The string value of a node is a string and can be extracted by applying the fn:string function to the node. The string value for each kind of node is defined by the dm:string-value accessor in [XQuery 1.0 and XPath 2.0 Data Model (http://www.w3.org/TR/2004/WD-xquery-20040723/#datamodel)]. Element and attribute nodes have a type annotation, which represents (in an implementation-dependent (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent) way) the dynamic (run-time) type (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-type) of the node. In the [XQuery 1.0 and XPath 2.0 Data Model (http://www.w3.org/TR/2004/WD-xquery-20040723/#datamodel)], type annotation is defined by the dm:type-name accessor; however, XQuery does not provide a way to directly access the type annotation of an element or attribute node.
数据模型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-datamodel)中,每个节点都有一个类型值字符串值。一个节点的类型值是一个原子值的序列,并且能通过对该节点作用fn:data函数抽取出该序列。在[XQuery 1.0 and XPath 2.0 Data Model (http://www.w3.org/TR/2004/WD-xquery-20040723/#datamodel)]中,每种节点的类型值都被dm:typed-value存取器定义了。一个节点的字符串值是一个字符串,而且能够对该节点作用fn:string函数抽取出该字符串值。每种节点的字符串值都被[XQuery 1.0 and XPath 2.0 Data Model (http://www.w3.org/TR/2004/WD-xquery-20040723/#datamodel)]中的dm:string-value存取器定义了。元素和属性节点有一个类型标注,表示(依赖于实现 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent)地)该节点的动态 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-type)(运行时)类型。在[XQuery 1.0 and XPath 2.0 Data Model (http://www.w3.org/TR/2004/WD-xquery-20040723/#datamodel)]中,类型标注由dm:type-name存取器定义;但是,XQuery并没有提供直接访问一个元素或者属性节点的类型标注的方法。
The relationship between the typed value and the string value for various kinds of nodes is described and illustrated by examples below.
下面的例子描述和说明了各种节点的类型值和字符串值之间的关系。


For text and document nodes, the typed value of the node is the same as its string value, as an instance of the type xdt:untypedAtomic. (The string value of a document node is formed by concatenating the string values of all its descendant text nodes, in document order (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-document-order).)
对于文本和文档节点,节点的类型值和它的字符串值是相同的,都是类型xdt:untypedAtomic的一个实例。(一个文档节点的字符串值是它所有后裔文本节点的字符串值按照文档顺序 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-document-order)连接形成的。)


The typed value of a comment or processing instruction node is the same as its string value. It is an instance of the type xs:string.
一个注释(comment)或者处理指令节点的类型值与它的字符串值相同,都是xs:string类型的一个实例。


The typed value of an attribute node with the type annotation xdt:untypedAtomic is the same as its string value, as an instance of xdt:untypedAtomic. The typed value of an attribute node with any other type annotation is derived from its string value and type annotation using the lexical-to-value-space mapping defined in [XML Schema (http://www.w3.org/TR/2004/WD-xquery-20040723/#XMLSchema)] Part 2 for the relevant type.
类型标注为xdt:untypedAtomic的属性节点的类型值与它的字符串值相同,都是xdt:untypedAtomic的一个实例。其它类型标注的属性节点的类型值是从其字符串值和类型标注衍生而来,根据 [XML Schema (http://www.w3.org/TR/2004/WD-xquery-20040723/#XMLSchema)] Part 2中相关类型的词法到值空间映射(lexical-to-value-space)。
Example: A1 is an attribute having string value "3.14E-2" and type annotation xs:double. The typed value of A1 is the xs:double value whose lexical representation is 3.14E-2.
例:A1是一个属性,字符串值为“3.14E-2”,类型标注为xs:double。A1的类型值是xs:double类型的值,其词法表示为 3.14E-2。
Example: A2 is an attribute with type annotation xs:IDREFS, which is a list datatype derived from the atomic datatype xs:IDREF. Its string value is "bar baz faz". The typed value of A2 is a sequence of three atomic values ("bar", "baz", "faz"), each of type xs:IDREF. The typed value of a node is never treated as an instance of a named list type. Instead, if the type annotation of a node is a list type (such as xs:IDREFS), its typed value is treated as a sequence of the atomic type from which it is derived (such as xs:IDREF).
例:A2是一个属性,类型标注为xs:IDREFS,这是从原子数据类型xs:IDREF衍生而来的列表数据类型。它的字符串值为“bar baz faz”。A2的类型值是含有三个原子值(“bar”, “baz”, “faz”)的序列,每个原子值都是xs:IDREF类型。一个节点的类型值从来不会当作一个命名列表类型的实例。如果一个节点的类型标注为列表类型(如xs:IDREFS),它的类型值被视为衍生它的原子类型(如xs:IDREF)的序列。


For an element node, the relationship between typed value and string value depends on the node's type annotation, as follows:
对于一个元素节点,类型值和字符串值之间的关系取决于节点的类型标注,具体如下:


If the type annotation is xdt:untyped or denotes a complex type with mixed content (including xs:anyType), then the typed value of the node is equal to its string value, as an instance of xdt:untypedAtomic.
如果类型标注为xdt:untyped或者表示有混合内容(包括xs:anyType)的复杂类型,那么该节点的类型值和它的字符串值是相等的,都是xdt:untypedAtomic的一个实例。
Example: E1 is an element node having type annotation xdt:untyped and string value "1999-05-31". The typed value of E1 is "1999-05-31", as an instance of xdt:untypedAtomic.
例:E1是一个元素节点,类型标注为xdt:untyped,字符串值为“1999-05-31”。E1的类型值为“1999-05-31”,是xdt:untypedAtomic的一个实例。
Example: E2 is an element node with the type annotation formula, which is a complex type with mixed content. The content of E2 consists of the character "H", a child element named subscript with string value "2", and the character "O". The typed value of E2 is "H2O" as an instance of xdt:untypedAtomic.
例2:E2是一个元素节点,类型标注为formula,这是一个有混合内容的复杂类型。E2的内容由字符“H”,一个名为subscript的子元素且字符串值为“2”,以及字符“0”。E2的类型值为“H20”,是xdt:untypedAtomic的一个实例。


If the type annotation denotes a simple type or a complex type with simple content, then the typed value of the node is derived from its string value and its type annotation in a way that is consistent with schema validation.
如果类型标注表示一个简单类型或者简单内容的复杂类型,那么按照与模式验证一致的方式,该节点的类型值从它的字符串值和它的类型标注衍生而来。
Example: E3 is an element node with the type annotation cost, which is a complex type that has several attributes and a simple content type of xs:decimal. The string value of E3 is "74.95". The typed value of E3 is 74.95, as an instance of xs:decimal.
例:E3是一个元素节点,类型标注为cost,这是一个复杂类型,有多个属性和xs:decimal类型的简单内容。E3的字符串内容是“74.95”,类型值是74.95,是xs:decimal的一个实例。
Example: E4 is an element node with the type annotation hatsizelist, which is a simple type derived from the atomic type hatsize, which in turn is derived from xs:integer. The string value of E4 is "7 8 9". The typed value of E4 is a sequence of three values (7, 8, 9), each of type hatsize.
例:E4是一个元素节点,类型标注为hatsizelist,这是从原子类型hatsize衍生而来的简单类型,而hatsize又是从xs:integer衍生而来。E4的字符串值是“7 8 9”,E4的类型值是含有三个值的序列(7, 8, 9),每个都是hatsize类型的。


If the type annotation denotes a complex type with empty content, then the typed value of the node is the empty sequence and its string value is the zero-length string.
如果类型标注表示一个内容为空的复杂类型,那么该节点的类型值是空序列,他的字符串值为长度为零的字符串。


If the type annotation denotes a complex type with element-only content, then the typed value of the node is undefined. The fn:data function raises a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) [err:XP0007 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0007)] when applied to such a node.
如果类型标注表示一个复杂类型,内容只能是元素,那么该节点的类型值是未定义的。当把fn:data函数作用到该节点时会引发 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error)一个类型错误 [err:XP0007 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0007)]。
Example: E5 is an element node with the type annotation weather, which is a complex type whose content type specifies element-only. E5 has two child elements named temperature and precipitation. The typed value of E5 is undefined, and the fn:data function applied to E5 raises an error.
例:E5是一个元素类型,类型标注为weather,这是一个复杂类型,其内容类型规定为 element-only。E5有两个孩子元素,名字分别为temperature和precipitation。E5的类型值是未定义的,fn:data作用到E5时会引发一个错误。

2.4.3 SequenceType Syntax

2..4.3 序列类型语法

[Definition: 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.]
[定义:当需要引用XQuery表达式中的一个类型时,就要用到序列类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SequenceType)序列类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SequenceType)这个名字的意思是这个语法是用来描述XQuery值的类型的,XQuery的值永远是一个序列。]





















[110]    SequenceType (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-SequenceType)    ::=   

(ItemType (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ItemType) OccurrenceIndicator (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-OccurrenceIndicator)?)

| ("empty" "(" ")")

[112]   

ItemType (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-ItemType)

   ::=   

AtomicType (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AtomicType) | KindTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-KindTest) | ("item" "(" ")")

[111]   

OccurrenceIndicator (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-OccurrenceIndicator)

   ::=   

"?" | "*" | "+"

[113]   

AtomicType (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-AtomicType)

   ::=   

QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-QName)

[114]   

KindTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-KindTest)

   ::=   

DocumentTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-DocumentTest)

| ElementTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementTest)

| AttributeTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeTest)

| SchemaElementTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaElementTest)

| SchemaAttributeTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaAttributeTest)

| PITest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-PITest)

| CommentTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-CommentTest)

| TextTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TextTest)

| AnyKindTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AnyKindTest)

[116]   

DocumentTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-DocumentTest)

   ::=   

"document-node" "(" (ElementTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementTest) | SchemaElementTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaElementTest))? ")"

[124]   

ElementTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-ElementTest)

   ::=   

"element" "(" (ElementNameOrWildcard (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementNameOrWildcard) ("," TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName) "?"?)?)? ")"

[126]   

SchemaElementTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-SchemaElementTest)

   ::=   

"schema-element" "(" ElementDeclaration (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementDeclaration) ")"

[127]   

ElementDeclaration (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-ElementDeclaration)

   ::=   

ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName)

[120]   

AttributeTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-AttributeTest)

   ::=   

"attribute" "(" (AttribNameOrWildcard (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttribNameOrWildcard) ("," TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName))?)? ")"

[122]   

SchemaAttributeTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-SchemaAttributeTest)

   ::=   

"schema-attribute" "(" AttributeDeclaration (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeDeclaration) ")"

[123]   

AttributeDeclaration (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-AttributeDeclaration)

   ::=   

AttributeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeName)

[125]   

ElementNameOrWildcard (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-ElementNameOrWildcard)

   ::=   

ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName) | "*"

[129]   

ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-ElementName)

   ::=   

QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-QName)

[121]   

AttribNameOrWildcard (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-AttribNameOrWildcard)

   ::=   

AttributeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeName) | "*"

[128]   

AttributeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-AttributeName)

   ::=   

QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-QName)

[130]   

TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-TypeName)

   ::=   

QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-QName)

[119]   

PITest (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-PITest)

   ::=   

"processing-instruction" "(" (NCName (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-NCName) | StringLiteral (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-StringLiteral))? ")"

[118]   

CommentTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-CommentTest)

   ::=   

"comment" "(" ")"

[117]   

TextTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-TextTest)

   ::=   

"text" "(" ")"

[115]   

AnyKindTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-AnyKindTest)

   ::=   

"node" "(" ")"

Here are some examples of SequenceTypes (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SequenceType) that might be used in XQuery expressions:
这里是XQuery表达式中可能使用的序列类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SequenceType)的例子:


xs:date refers to the built-in atomic Schema type named xs:date
xs:date引用名为xs:date内置原子模式类型


attribute()? refers to an optional attribute

 attribute()?引用一个可选的属性

element() refers to any element
element()引用任意元素


element(po:shipto, po:address) refers to an element that has the name po:shipto and has the type annotation po:address (or a type derived from po:address)

 element(po:shipto, po:address)引用一个名为po:shipto,类型标注为po:address(或一个从po:address衍生的类型)的元素

element(*, po:address) refers to an element of any name that has the type annotation po:address (or a type derived from po:address)

 element(*, po:address)引用一个任意名字、类型标注为po:address(或一个从po:address衍生的类型)的元素

element(customer) refers to an element named customer of any type
element(customer)引用一个名为customer任意类型的元素


schema-element(customer) refers to an element named customer whose type annotation matches the type declared for a customer element in the in-scope element declarations (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-elems)

 schema-element(customer)引用一个名为customer的元素,其类型标注与作用域内元素声明 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-elems)里为customer元素声明的类型匹配

node()* refers to a sequence of zero or more nodes of any type
node()*引用含有零个或多个任意类型的节点的序列


item()+ refers to a sequence of one or more nodes or atomic values
item()+引用了含有一个或多个节点或原子值的序列

2.4.4 SequenceType Matching

[Definition: 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.] For example, an instance of expression returns true if the actual type of a given value matches a given type, or false if it does not.
[定义:在表达式的计算期间,有时需要判断一个已知类型的值是否与一个预期类型匹配,用序列类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SequenceType)的语法表达。这个过程被称为序列类型匹配。]例如 ,如果给定值的实际类型与给定类型匹配,一个表达式的 instance 就返回true,否则返回false。
Note:
注意:
In this specification, the word "type", when used without modification, represents a type that can be expressed using the SequenceType (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SequenceType) syntax. When we refer specifically to XML Schema simple or complex types, appropriate modifiers are used to make this clear.
在本规范中,词“type”如果使用时没有修饰,表示可以用序列类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SequenceType)语法表达的一个类型。当我们具体引用XML Schema的简单或者复杂类型时,会加上一些修饰语是表达清楚。
QNames appearing in a SequenceType (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SequenceType) have their prefixes expanded to namespace URIs by means of the statically known namespaces (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-namespaces) and the default element/type namespace (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-def-elemtype-ns). As usual, two QNames are considered to be equal if their local parts are the same and their namespace URI's are the same.
静态已知命名空间 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-namespaces)缺省元素/类型命名空间 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-def-elemtype-ns),出现在序列类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SequenceType)中的QName将它们的前缀扩展为命名空间URI。同样地,当两个QName的本地部分相同而且它们的命名空间URI相同时,它们认为是相等的。
[Definition: The use of a value whose actual type is derived from the expected type is known as subtype substitution.] Subtype substitution does not change the actual type of a value. For example, if an xs:integer value is used where an xs:decimal value is expected, the value retains its type as xs:integer.
[定义:如果使用的值的实际类型是期望类型的衍生类型,则称为子类型替换。]子类型替换不会改变一个值的实际类型。例如,如果在期望xs:decimal值的地方使用xs:integer值,这个值仍然保持其类型为xs:integer。
The rules for SequenceType matching (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-sequencetype-matching) compare the actual type of a value with an expected type. These rules are a subset of the formal rules that match a value with an expected type defined in [XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)], because the Formal Semantics must be able to match a value with any XML Schema type, whereas the rules below only match values against those types expressible by the SequenceType (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SequenceType) syntax.
序列类型匹配 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-sequencetype-matching)规则比较一个值的实际类型和期望类型。这些规则是[XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)]中定义的一个值与一个预期类型匹配规则的一个子集,因为正式语义必须能将一个值与任意XML Schema类型相比,而下面的规则只比较值和那些能用序列类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SequenceType)语法表达的类型。
Some of the rules for SequenceType matching (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-sequencetype-matching) require determining whether a given type name is the same as or derived from an expected type name. The given type name may be "known" (defined in the in-scope schema definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd)), or "unknown" (not defined in the in-scope schema definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd)). An unknown type name might be encountered, for example, if a source document has been validated using a schema that was not imported into the static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context). In this case, an implementation is allowed (but is not required) to provide an implementation-dependent (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent) mechanism for determining whether the unknown type name is derived from the expected type name. For example, an implementation might maintain a data dictionary containing information about type hierarchies.
某些序列类型匹配 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-sequencetype-matching)的规则要求判断一个给定类型名是否与期望类型名相同或者从期望类型名衍生而来。这个给定类型名可能是已知的(在作用域内模式定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd)中定义了)也可能是未知的(没有在作用域内模式定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd)中定义)。可能碰到一个未知类型名,例如,一个原文档已经用一个模式验证但是该模式没有导入到静态语境 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context)中。在这种情形下,实现可以提供一种依赖于实现 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent)的机制来判断该未知类型名是否从期望类型名衍生而来。例如,实现可以维护一个包含关系类型层次的信息的数据字典。
The definition of SequenceType matching (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-sequencetype-matching) relies on a pseudo-function named derives-from(AT, ET), which takes an an actual simple or complex type name AT and an expected simple or complex type name ET, and either returns a boolean value or raises a type error. [err:XP0004 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0004)][err:XP0006 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0006)] The pseudo-function derives-from is defined below and is defined formally in [XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)].
序列类型匹配 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-sequencetype-matching)的定义依赖于一个名为derives-from(AT, ET)的伪函数,它接受一个实际的简单或复杂类型名AT和一个期望的简单或复杂类型名ET,返回一个布尔值或者引发一个类型错误。[err:XP0004 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0004)][err:XP0006 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0006)]。下面定义了伪函数derives-from,它在 [XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)] 中被正式定义。


derives-from(AT, ET) returns true if any of the following three conditions is true:
如果下列三个条件之一成立,derives-from(AT, ET)返回true:


AT is a type name found in the in-scope schema definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd), and is the same as ET or is derived by restriction or extension from ET
AT作用域内模式定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd)中的类型名,它与ET相同,或者通过限制或者扩展ET衍生而来。


AT is a type name not found in the in-scope schema definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd), and an implementation-dependent (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent) mechanism is able to determine that AT is derived by restriction from ET
AT不在作用域内模式定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd)中,而且一个依赖于实现 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent)的机制能够判断AT是通过限制ET衍生而来。<ER>


There exists some type name IT such that derives-from(IT, ET) and derives-from(AT, IT) are true.
存在某种类型IT满足derives-from(IT,ET)和derives-from(AT,IT)都是true。


derives-from(AT, ET) returns false if either the first and third or the second and third of the following conditions are true:
如果下列条件的第一、三个或者第二和第三个条件是真,derives-from(AT,ET)返回false:


AT is a type name found in the in-scope schema definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd), and is not the same as ET, and is not is derived by restriction or extension from ET
AT作用域内模式定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd)中的类型名,它与ET不同,并且不是通过限制或扩展ET衍生而来。


AT is a type name not found in the in-scope schema definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd), and an implementation-dependent (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent) mechanism is able to determine that AT is not derived by restriction from ET
AT不是作用域内模式定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd)中的类型名,而且一个依赖于实现 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent)的机制能够判断AT不是通过限制ET衍生而来。


No type name IT exists such that derives-from(IT, ET) and derives-from(AT, IT) are true.
不存在某种类型IT满足derives-from(IT,ET)和derives-from(AT,IT)都是真。


derives-from(AT, ET) raises a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) [err:XP0004 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0004)][err:XP0006 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0006)] if:
在下列条件下,derives-from(AT,ET)引发一个类型错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) [err:XP0004 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0004)][err:XP0006 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0006)]:


ET is an unknown type, or
ET是未知的类型,或者


AT is an unknown type, and the implementation is not able to determine whether AT is derived by restriction from ET.
AT是未知的类型,而且实现不能判断AT是否通过限制ET衍生而来。
Note:
注意:
The derives-from pseudo-function cannot be written as a real XQuery function, because types are not valid function parameters.
derives-from伪函数不能写成一个实际的XQuery函数,因为类型不是有效的函数参数。
The rules for SequenceType matching (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-sequencetype-matching) are given below, with examples (the examples are for purposes of illustration, and do not cover all possible cases).
下面给出了序列类型匹配 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-sequencetype-matching)的规则,并给出了例子(这些例子只是为了解释,并没有考虑所有情况)。

2.4.4.1 Matching a SequenceType and a Value
2.4.4.1 匹配一个序列类型和一个值




The SequenceType empty() matches a value that is the empty sequence.
序列类型empty()与一个空序列值匹配。


An ItemType (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ItemType) with no OccurrenceIndicator (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-OccurrenceIndicator) matches any value that contains exactly one item if the ItemType (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ItemType) matches that item (see 2.4.4.2 Matching an ItemType and an Item).
一个不带出现指示器 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-OccurrenceIndicator)(OccurrenceIndicator)的项类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ItemType)与一个只含一个项的值匹配,如果该项类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ItemType)与该项匹配(见2.4.4.2 匹配项类型与项)。


An ItemType (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ItemType) with an OccurrenceIndicator (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-OccurrenceIndicator) matches a value if the number of items in the value matches the OccurrenceIndicator (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-OccurrenceIndicator) and the ItemType (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ItemType) matches each of the items in the value.
一个带有出现指示器 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-OccurrenceIndicator)项类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ItemType)与一个值匹配,条件是值中项的数目与出现指示器 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-OccurrenceIndicator)匹配,而且项类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ItemType)与值中的每个项都匹配。
An OccurrenceIndicator (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-OccurrenceIndicator) specifies the number of items in a sequence, as follows:
一个出现指示器 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-OccurrenceIndicator)指出了一个序列中的项的数目,如下:


? matches zero or one items
?与零或一个项匹配


  • matches zero or more items
  • 与零或多个项匹配

+ matches one or more items
+与一或多个匹配项
As a consequence of these rules, any SequenceType whose OccurrenceIndicator (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-OccurrenceIndicator) is * or ? matches a value that is an empty sequence.
有这些规则可以得到,出现指示器 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-OccurrenceIndicator)为*或?的任意序列类型与一个空序列的值匹配。

2.4.4.2 Matching an ItemType and an Item
2.4.4.2 匹配一个项类型与一个项




An ItemType (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ItemType) consisting simply of a QName is interpreted as an AtomicType (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AtomicType). An AtomicType AtomicType matches an atomic value whose actual type is AT if derives-from(AT, AtomicType) is true. If a QName that is used as an AtomicType (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AtomicType) is not defined as an atomic type in the in-scope type definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-types), a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) is raised. [err:XP0051 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0051)]
一个仅仅只有一个QName组成的项类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ItemType)(ItemType)被视为一个原子类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AtomicType)(AtomicType)。当一个原子值的实际类型是AT且derives-from(AT,AtomicType)为真时,原子类型AtomicType与该原子值匹配。如果在作用域内类型定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-types)中,一个用作原子类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AtomicType)的QName不是定义为原子类型(atomic type),就会引发一个静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)。[err:XP0051 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0051)]
Example: The AtomicType (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AtomicType) xs:decimal matches the value 12.34 (a decimal literal). xs:decimal also matches a value whose type is shoesize, if shoesize is an atomic type derived by restriction from xs:decimal.
例:原子类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AtomicType) xs:decimal 与值12.34(一个小数字面值)匹配。如果shoesize 是通过约束xs:decimal而衍生的一个原子类型,则 xs:decimal 也与一个类型为shoesize的值匹配。
Note:
注意:
The names of non-atomic types such as xs:IDREFS are not accepted in this context, but can often be replaced by an atomic type with an occurrence indicator, such as xs:IDREF*.
像xs:IDREFS这样的非原子类型的名字在这种语境下不能接受,但是可以被一个带有出现指示器的原子类型取代,如 xs:IDREF*。


item() matches any single item.
item()与任意单元素项匹配。
Example: item() matches the atomic value 1 or the element <a/>.
如:item()与原子值1或元素<a/>匹配。


node() matches any node.
node()与任何节点匹配。


text() matches any text node.
text()与任何文本节点匹配。


processing-instruction() matches any processing-instruction node.
processing-instruction()与任何处理指令节点匹配。


processing-instruction(N) matches any processing-instruction node whose name (called its "PITarget" in XML) is equal to N, where N is an NCName.
processing-instruction(N)与任何名称(在XML中称为“PITarget”)等于N的处理指令节点相匹配,其中N是一个NCName。
Example: processing-instruction(xml-stylesheet) matches any processing instruction whose PITarget is xml-stylesheet.
例:processing-instruction(xml-stylesheet)与任何PITarget为xml-stylesheet的处理指令匹配。
For backward compatibility with XPath 1.0, the PITarget of a processing instruction may also be expressed as a string literal, as in this example: processing-instruction("xml-stylesheet").
为了与XPath 1.0向后兼容,一个处理指令的PITarget也可以用一个字符串字面值表示,如这个例子:processing-instruction("xml-stylesheet")。


comment() matches any comment node.
comment()与任何注释节点匹配。


document-node() matches any document node.
document-node()与任何文档节点匹配。


document-node(E) matches any document node that contains exactly one element node, optionally accompanied by one or more comment and processing instruction nodes, if E is an ElementTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementTest) or SchemaElementTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaElementTest) that matches the element node (see 2.4.4.3 Element Test and 2.4.4.4 Schema Element Test).
document-node(E)与任何只包含一个元素节点的文档节点匹配,也可以带上一个或多个注释或处理指令节点,条件是E是与该元素节点匹配的一个元素测试 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementTest)(ElementTest)或者模式元素测试 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaElementTest)(SchemaElementTest)。(见2.4.4.3 元素测试2.4.4.4 模式元素测试)。
Example: document-node(element(book)) matches a document node containing exactly one element node that is matched by the ElementTest element(book).
例:如果一个文档节点只包含一个元素节点且该节点与元素测试element(book)匹配,则document-node(element(book))与该文档节点匹配。


An ItemType (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ItemType) that is an ElementTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementTest), SchemaElementTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaElementTest), AttributeTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeTest), or SchemaAttributeTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaAttributeTest) matches an element or attribute node as described in the following sections.
一个项类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ItemType)如果是元素测试 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementTest)模式元素测试 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaElementTest)属性测试 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeTest)模式属性测试 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaAttributeTest),则它按照下一节中介绍的方式与一个元素或属性节点匹配。

2.4.4.3 Element Test
2.4.4.3 元素测试



An ElementTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementTest) is used to match an element node by its name and/or type. An ElementTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementTest) any take any of the following forms. In these forms, ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName) and TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName) may be any QNames, and need not be present in the in-scope schema definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd). Note that substitution groups (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-substitution-group) do not affect the semantics of ElementTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementTest).
元素测试 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementTest)用来根据名称和/或类型来匹配一个元素节点。一个元素测试 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementTest)可以采用如下任意一种形式。在这些形式中,元素名 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName)(ElementName)和类型名 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName)(TypeName)可以是任意QName,且不一定要在作用域内模式定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd)中。注意置换组不会影响元素测试 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementTest)的语义。


element() and element(*) match any single element node, regardless of its name or type.
element()和element(*)与任意单个元素节点匹配,不管其名称和类型是什么。


element(ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName)) matches any element node whose name is ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName), regardless of its type or nilled property.
element(ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName))与任意名称为ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName)的元素节点匹配,不管其类型或nilled属性(nilled property)是什么。
Example: element(person) matches any element node whose name is person.
例:element(person)与任意名为person的元素节点匹配。


element(ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName), TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName)) matches an element node whose name is ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName) if derives-from(AT, TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName) ) is true, where AT is the type of the element node, and the nilled property of the node is false.
element(ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName), TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName))与名为ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName)的元素节点匹配,条件是derives-from(AT, TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName)) 为true,其中AT为该元素节点的类型,且nilled属性(nilled property)是true。
Example: element(person, surgeon) matches a non-nilled element node whose name is person and whose type annotation is surgeon.
例:element(person, surgeon)与名为person,类型标注为surgeon的元素节点匹配。


element(ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName), TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName) ?) matches an element node whose name is ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName) if derives-from(AT, TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName)) is true, where AT is the type of the element node. The nilled property of the node may be either true or false.
element(ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName), TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName)?)与名为ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName)的元素节点匹配,条件是derives-from(AT,TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName))为真,其中,AT是元素节点的类型。节点的nilled属性可以为true或false。
Example: element(person, surgeon?) matches a nilled or non-nilled element node whose name is person and whose type annotation is surgeon.
例:element(person, surgeon?)与名为person,类型标注为surgeonde的nilled或non-nilled的元素节点匹配。


element(*, TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName)) matches an element node regardless of its name, if derives-from(AT, TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName) ) is true, where AT is the type of the element node, and the nilled property of the node is false.
element(*, TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName))与任意名称的元素节点匹配,条件是derives-from(AT, TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName))为true,其中AT是该元素节点的类型,且该节点的nilled属性为false。
Example: element(*, surgeon) matches any non-nilled element node whose type annotation is surgeon, regardless of its name.
例:element(*, surgeon)与任意类型标注为surgeon的non-nilled元素节点匹配,不管其名称是什么。


element(*, TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName) ?) matches an element node regardless of its name, if derives-from(AT, TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName) ) is true, where AT is the type of the element node. The nilled property of the node may be either true or false.
element(*, TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName)?)与任意名称的元素节点匹配,条件是derives-from(AT, TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName))为真,其中AT是该元素节点的类型,该元素节点的nilled属性可以是true 或false。
Example: element(*, surgeon?) matches any nilled or non-nilled element node whose type annotation is surgeon, regardless of its name.
例:element(*, surgeon?)与任意类型标注为surgeon的nilled或non-nilled的元素节点匹配,不管其名称是什么。

2.4.4.4 Schema Element Test
2.4.4.4 模式元素测试



A SchemaElementTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaElementTest) matches an element node against a corresponding element declaration found in the in-scope element declarations (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-elems). It takes the following form:
一个模式元素测试 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaElementTest)将一个元素节点与作用域内元素定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-elems)中对应的元素声明进行匹配,它有如下形式:
schema-element(ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName))
If the ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName) specified in the SchemaElementTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaElementTest) is not found in the in-scope element declarations (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-elems), a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) is raised. [err:XP0008 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0008)]
如果模式元素测试 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaElementTest)中的元素名 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName)不在作用域内元素声明 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-elems)中,就会引发一个静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)。[err:XP0008 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0008)]
A SchemaElementTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaElementTest) matches a candidate element node if all three of the following conditions are satisfied:
如果下列三个条件都满足,一个模式元素测试 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaElementTest)就与一个候选元素节点匹配。


The name of the candidate node matches the specified ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName) or matches the name of an element in a substitution group (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-substitution-group) headed by an element named ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName).
候选节点的名称与指定的元素名 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName)匹配,或与名为元素名 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName)的元素开头的置换组 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-substitution-group)中的一个元素的名称匹配。


derives-from(AT, ET) is true, where AT is the type of the candidate node and ET is the type declared for element ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName) in the in-scope element declarations (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-elems).
derives-from(AT, ET)为true,其中AT为候选节点的类型,ET是在作用域内元素声明 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-elems)中为元素ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName)声明的类型。


Either the nilled property of the candidate node is false, or the element declaration for ElementName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName) in the in-scope element declarations (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-elems) is nillable.
候选节点的nilled属性为false,或者作用域内元素声明 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-elems)中对于元素名 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ElementName)的元素声明是nillable。
Example: The SchemaElementTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaElementTest) schema-element(customer) matches a candidate element node if customer is a top-level element declaration in the in-scope element declarations (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-elems), the name of the candidate node is customer or is in a substitution group (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-substitution-group) headed by customer, the type of the candidate node is the same as or derived from the type declared for the customer element, and either the candidate node is not nilled or customer is declared to be nillable.
例:模式元素测试 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaElementTest)schema-element(customer)与一个候选元素节点匹配,条件是customer是作用域内元素声明 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-elems)中的一个顶层元素声明,候选节点的名称是customer或在customer开头的置换组 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-substitution-group)中,候选节点的类型与为customer声明的类型相同或者从它衍生而来,而且候选节点不是nilled或者customer被声明为nillable。

2.4.4.5 Attribute Test
2.4.4.5 属性测试



An AttributeTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeTest) is used to match an attribute node by its name and/or type. An AttributeTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeTest) any take any of the following forms. In these forms, AttributeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeName) and TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName) may be any QNames, and need not be present in the in-scope schema definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd).
一个属性测试 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeTest)用来根据它的名称和/或类型来匹配一个属性节点。一个属性测试 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeTest)可以采用如下任意一种形式。在这些形式中,AttributeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeName)TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName)可以是任意QName,并且不一定要在作用域内模式定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd)中。


attribute() and attribute(*) match any single attribute node, regardless of its name or type.
attribute()和attribute(*) 与任何单个属性节点匹配,不管其名称和类型是什么。


attribute(AttributeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeName)) matches any attribute node whose name is AttributeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeName), regardless of its type or nilled property.
attribute(AttributeName)与任意名为AttributeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeName)的属性节点匹配,不管其类型或nilled属性(property)是什么。
Example: attribute(price) matches any attribute node whose name is price.
例:attribute(price)与任意名为price的属性节点匹配。


attribute(AttributeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeName), TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName)) matches an attribute node whose name is AttributeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeName) if derives-from(AT, TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName) ) is true, where AT is the type of the attribute node.
attribute(AttributeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeName), TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName))与一个名为AttributeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeName)的属性节点匹配,条件是derives-from(AT, TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName))为真,其中AT为属性节点的类型。
Example: attribute(price, currency) matches an attribute node whose name is price and whose type annotation is currency.
例:attribute(price, currency)与一个名为price,类型标注为currency的属性节点匹配。


attribute(*, TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName)) matches an attribute node regardless of its name, if derives-from(AT, TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName)) is true, where AT is the type of the attribute node.
attribute(*, TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName))与任意名称的属性节点匹配,条件是derives-from(AT, TypeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-TypeName))为真,其中AT是属性节点的类型。
Example: attribute(*, currency) matches any attribute node whose type annotation is currency, regardless of its name.
例:attribute(*, currency)与任意类型标注为currency的属性节点匹配,不管其名称是什么。

2.4.4.6 Schema Attribute Test
2.4.4.6 模式属性测试



A SchemaAttributeTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaAttributeTest) matches an attribute node against a corresponding attribute declaration found in the in-scope attribute declarations (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-attrs). It takes the following form:
一个模式属性测试 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaAttributeTest)将一个属性节点与作用域内属性声明 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-attrs)中对应的属性声明进行匹配,它的形式为:
schema-attribute(AttributeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeName))
If the AttributeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeName) specified in the SchemaAttributeTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaAttributeTest) is not found in the in-scope attribute declarations (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-attrs), a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) is raised. [err:XP0008 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0008)]
如果模式属性测试 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaAttributeTest)中指定的属性名 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeName)不在作用域内属性声明 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-attrs)中,就会引发一个静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)。[err:XP0008 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0008)]
A SchemaAttributeTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaAttributeTest) matches a candidate attribute node if both of the following conditions are satisfied:
如果下列两个条件都成立,一个模式属性测试与一个候选属性节点匹配:


The name of the candidate node matches the specified AttributeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeName).
候选节点的名称与指定属性名 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeName)匹配。


derives-from(AT, ET) is true, where AT is the type of the candidate node and ET is the type declared for attribute AttributeName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeName) in the in-scope attribute declarations (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-attrs).
derives-from(AT,ET)为真,其中AT为候选节点的类型,ET作用域内属性声明 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-attrs)中为属性属性名 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeName)声明的类型。
Example: The SchemaAttributeTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaAttributeTest) schema-attribute(color) matches a candidate attribute node if color is a top-level attribute declaration in the in-scope attribute declarations (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-attrs), the name of the candidate node is color, and the type of the candidate node is the same as or derived from the type declared for the color attribute.
例:模式属性测试 (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-SchemaAttributeTest)schema-attribute(color)与一个候选属性节点匹配,条件是color是作用域内属性声明 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-attrs)中的顶层属性声明,该候选节点的名称为color,候选节点的类型与为color属性声明的类型相同或从它衍生而来。

2.5 Error Handling

2.5 错误处理

2.5.1 Kinds of Errors

2.5.1 错误种类

As described in 2.2.3 Expression Processing, XQuery defines an analysis phase (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis), which does not depend on input data, and an evaluation phase (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-evaluation), which does depend on input data. Errors may be raised during each phase.
2.2.3 表达式处理所述,XQuery定义了一个分析阶段 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis),它不依赖于输入数据,和一个计算阶段 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-evaluation),它则依赖于输入数据。在每个阶段都可能引发错误。
[Definition: 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). ]
定义:一个静态错误是一个必须在静态分析阶段发现的错误。一个语法错误是一个静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)的例子,在分析阶段报告静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)的方式是实现定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-defined)的。]
[Definition: 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. ]
[定义:一个动态错误是一个必须在计算阶段发现但可能在分析阶段发现的错误。数值溢出时一个动态错误的例子。]
[Definition: 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. ]
[定义:一个类型错误可能在分析阶段或计算阶段引发。在分析阶段,当一个表达式的静态类型 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-type)与该表达式所处的语境期望的类型不匹配时,就会出现一个类型错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error)。在计算阶段,当一个值的动态类型与该值出现的语境期望的类型不匹配时,就会出现一个类型错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error)。]
The outcome of the analysis phase (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis) is either success or one or more type errors (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) and/or static errors (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error). The result of the evaluation phase (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-evaluation) is either a result value, a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error), or a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error).
分析阶段 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis)的结果要么是成功要么是一个或多个类型错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error)和/或静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)计算阶段 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-evaluation)的结果是一个结果值,一个类型错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error),或一个动态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error)
If any expression (at any level) can be evaluated during the analysis phase (because all its explicit operands are known and it has no dependencies on the dynamic context), then any error in performing this evaluation may be reported as a static error. However, the fn:error() function must not be evaluated during the analysis phase. For example, an implementation is allowed (but not required) to treat the following expression as a static error, because it calls a constructor function with a constant string that is not in the lexical space of the target type:
如果一个表达式(任何层次上的)可以在分析阶段计算(因为它所有的显式操作数都是已知的且不存在对动态语境的依赖),那么执行这个计算过程中的任何错误都会报告为一个静态错误。然而,fn:error()不能在分析阶段计算。例如,一个实现可以(但不是需要)将下面的表达式当作是一个静态错误,因为它调用了一个带有常量字符串的构造器函数,但该字符串不在目标类型的词法空间中:


xs:date("Next Tuesday")


If the Static Typing Feature (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-typing-feature) is not in effect but an implementation can nevertheless determine during the analysis phase that an expression will necessarily raise a type error, the implementation may report that error during the analysis phase.
如果静态类型特征 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-typing-feature)不起作用,但是一个实现能在分析阶段判断一个表达式一定会引发一个类型错误,该实现可以在分析阶段报告这个错误。
In addition to static errors (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error), dynamic errors (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error), and type errors (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error), an XQuery implementation may raise warnings, either during the analysis phase or the evaluation phase. The circumstances in which warnings are raised, and the ways in which warnings are handled, are implementation-defined (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-defined).
除了静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)动态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error)类型错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error)之外,一个XQuery实现可以引发警告,或者在分析阶段或者计算阶段。引发警告的时机和警告处理的方式都是[http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-defined 实现定义的。
In addition to the errors defined in this specification, an implementation may raise a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) if insufficient resources are available for processing a given expression. For example, an implementation may specify limitations on the maximum numbers or sizes of various objects. These limitations, and the consequences of exceeding them, are implementation-dependent (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent).
除了本规范定义的错误之外,如果在处理一个给定表达式时资源不足,一个实现可以引发一个http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error 动态错误]。例如,一个实现可能规定各种对象的最大数目或大小。这些限制以及超过它们的的后果都是依赖于实现 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent)的。

2.5.2 Handling Dynamic Errors

2.5.2 处理动态错误

Except as noted in this document, if any operand of an expression raises a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error), the expression also raises a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error). If an expression can validly return a value or raise a dynamic error, the implementation may choose to return the value or raise the dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error). For example, the logical expression expr1 and expr2 may return the value false if either operand returns false, or may raise a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) if either operand raises a dynamic error.
除了本文档提到的之外,如果一个表达式的任意操作数引发一个动态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error),该表达式也引发一个动态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error)。如果一个表达式能有根据地返回一个值或引发一个动态错误,实现可以选择返回该值或引发该动态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error)。例如,如果逻辑表达式expr1 and expr2的任意一个操作数返回false,则该表达式可以返回值false,或者如果任意一个操作数引发一个动态错误,则引发一个动态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error)
If more than one operand of an expression raises an error, the implementation may choose which error is raised by the expression. For example, in this expression:
如果一个表达式有一个以上的操作数引发错误,实现可以选择哪一个错误被该表达式引发。例如,在这个表达式里:


($x div $y) + xs:decimal($z)


both the sub-expressions ($x div $y) and xs:decimal($z) may raise an error. The implementation may choose which error is raised by the "+" expression. Once one operand raises an error, the implementation is not required, but is permitted, to evaluate any other operands.
两个子表达式($x div $y)和xs:decimal($z)都会引发错误。实现可以选择哪一个错误被该“+”表达式引发。一旦一个操作数引发一个错误,实现可以,但不是需要,计算任何其他的操作数。
[Definition: 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.] For example, an error value might be an integer, a string, a QName, or an element. An implementation may provide a mechanism whereby an application-defined error handler can process error values and produce diagnostics; in the absence of such an error handler, the string value of the error value may be used directly as an error message.
[定义:一个动态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error)携带了一个错误值,它可以是单个项,也可以是空序列。]例如,一个错误值可能是一个整数,一个字符串,一个QName或一个元素。一个实现可以提供一种机制,通过这种机制一个应用程序定义的错误处理程序能处理错误值并产生诊断;如果没有这样的错误处理程序,错误值的字符串值可以直接用作错误信息。
A dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) may be raised by a built-in function or operator. For example, the div operator raises an error if its second operand equals zero.
一个动态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error)可能被一个内置函数或操作符引发。例如,如果div操作符的第二个操作数等于零,它就会引发一个错误。
An error can be raised explicitly by calling the fn:error function, which only raises an error and never returns a value. This function is defined in [XQuery 1.0 and XPath 2.0 Functions and Operators (http://www.w3.org/TR/2004/WD-xquery-20040723/#FunctionsAndOperators)]. The fn:error function takes an optional item as its parameter, which is the error value (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-error-value). For example, the following function call raises a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) whose error value is a string:
一个错误可以通过调用fn:error函数显式地引发,它只引发一个错误而从不返回一个值。这个函数在[XQuery 1.0 and XPath 2.0 Functions and Operators (http://www.w3.org/TR/2004/WD-xquery-20040723/#FunctionsAndOperators)]中定义。fn:error函数带一个可选的项作为参数,那就是错误值。例如,下面的函数调用引发一个动态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error),其值为一个字符串:


fn:error(fn:concat("Unexpected value ", fn:string($v)))


2.5.3 Errors and Optimization

2.5.3 错误和优化

Because different implementations may choose to evaluate or optimize an expression in different ways, the detection and reporting of dynamic errors (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) is implementation-dependent (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent).
因为不同的实现可能选择以不同的方式来计算和优化一个表达式,动态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error)的检测和报告是依赖于实现 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent)的。
When an implementation is able to evaluate an expression without evaluating some subexpression, the implementation is never required to evaluate that subexpression solely to determine whether it raises a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error). For example, if a function parameter is never used in the body of the function, an implementation may choose whether to evaluate the expression bound to that parameter in a function call.
当一个实现能够无需计算某子表达式就可以计算一个表达式时,不要求这个实现去单独计算该子表达式以判断它是否引发了一个动态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error)。例如,如果在一个函数体中一个函数参数从来没有用到,一个实现可以选择是否计算一个函数调用中绑定到该参数的表达式。
Similarly, in evaluating an expression, an implementation is not required to search for data whose only possible effect on the result would be to raise an error, as illustrated in the following examples.
类似地,在计算一个表达式时,不要求一个实现查找那些对结果的唯一可能影响只是会引发错误的数据,下面的例子说明了这一点。


If an implementation can find (for example, by using an index) that at least one item returned by $expr1 in the following example has the value 47, it is allowed to return true as the result of the some expression, without searching for another item returned by $expr1 that would raise an error because it is not an integer.
如果一个实现能在如下的例子中发现(例如,通过索引)$expr1返回的项中至少一个有值47,就可以返回true作为该some表达式的结果,而无需查找$expr1返回的另一个可能引发一个错误的项,因为该项不是一个整数。


some $x in $expr1 satisfies $x = 47



In the following example, if an implementation can find (for example, by using an index) the product element-nodes that have an id child with the value 47, it is allowed to return these nodes as the result of the path expression, without searching for another product node that would raise an error because it has an id child whose value is not an integer.
在下面的例子中,如果一个实现能找出(例如,通过索引)满足有一个值为47的id孩子的product元素节点,就可以返回这些节点作为该路径表达式的结果,而无需查找另外的可能会引发一个错误的product节点,因为该节点有一个id孩子,但是其值不是一个整数。


//product[id = 47]


In some cases, an optimizer may be able to achieve substantial performance improvements by rearranging an expression so that the underlying operations are performed in a different order than that in which they are written. In such cases, errors may be raised that would not have been raised if the expression were evaluated as written. However, an expression must not be rearranged in a way that changes its result value in the absence of errors.
在某些情况下,优化器可能重写一个表达式,这样基本操作执行的顺序就不同于它们的书面顺序,通过这种方式使性能大幅提高。在这些情况下,某些错误可能会被引发,而如果表达式按照书面顺序计算的话它们本不会引发的。然而,一个表达式的重写不能在无错的情况下改变结果值。


The expression in the following example cannot raise a casting error if it is evaluated exactly as written (i.e., left to right). An implementation is permitted, however, to reorder the predicates to achieve better performance (for example, by taking advantage of an index). This reordering could cause the expression to raise an error.
下面例子中的表达式如果完全按照书面那样(即从左到右)计算不会引发转换错误。一个实现可以重新排列谓词来取得更好的性能(比如,借助于索引)。这种重排可能会使该表达式引发一个错误。


$N[@x castable as xs:date][xs:date(@x) gt xs:date("2000-01-01")]


To avoid unexpected errors caused by reordering of expressions, tests that are designed to prevent dynamic errors should be expressed using conditional or typeswitch expressions. Conditional and typeswitch expressions raise only dynamic errors that occur in the branch that is actually selected.
为了防止表达式的重排产生不可预期的错误,避免动态错误的测试应该用条件或开关表达式(typeswitch expression)表达。条件和开关表达式只会引发在实际选择的分支上发生的错误。


Unlike the previous example, the following example cannot raise a dynamic error if @x is not castable into an xs:date.
与前面的例子不同,下面的例子中@x不能转换为xs:date不会引发一个动态错误。


$N[if (@x castable as xs:date)

   then xs:date(@x) gt xs:date("2000-01-01")
else false()]


2.6 Optional Features

2.6 可选特征

XQuery defines several optional features, which are described in this section.
XQuery定义了一些可选特征,它们在这一节进行介绍。

2.6.1 Schema Import Feature

2.6.1 模式导入特征

[Definition: 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).] If more than one schema is imported, the definitions contained in these schemas are collected into a single pool of definitions. This pool of definitions must satisfy the conditions for schema validity set out in Sections 3 and 5 of [XML Schema (http://www.w3.org/TR/2004/WD-xquery-20040723/#XMLSchema)] Part 1. In brief, 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 definitions with the same expanded QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-expanded-qname) in the same symbol space. If any of these conditions is violated, a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) is raised.[err:XQ0012 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXQ0012)]
[定义:如果支持模式导入特征,一个 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-prolog)可能包含一个模式导入 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-schema-import)。导入的模式中的定义被加入到作用域内模式定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd)中。]如果一个以上模式被导入,这些模式中包含的定义被收集到一个定义库(pool)中。这个定义库必须满足[XML Schema (http://www.w3.org/TR/2004/WD-xquery-20040723/#XMLSchema)] part 1第3节和第5节制定的关于模式有效性的条件。简而言之,这些定义必须是有效的,它们必须是完整的,而且它们必须是唯一的——也就是说,定义库不能包含两个或更多在同一个符号空间中扩展QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-expanded-qname)相同的定义。如果违背这些条件中的任意一个,就会引发一个静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)。[err:XQ0012 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXQ0012)]

If an XQuery implementation that does not support the Schema Import Feature (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-schema-import-feature) encounters a schema import (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-schema-import), it raises a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error).[err:XQ0009 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXQ0009)] In such an implementation, the in-scope type definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-types) consist only of predefined type definitions, as described in C.1 Static Context Components.
如果一个不支持模式导入特征 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-schema-import-feature)的XQuery实现碰到一个模式导入 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-schema-import),它会引发一个静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)。[err:XQ0009 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXQ0009)]在这样的实现中,作用域内类型定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-is-types)仅仅只由预定义类型定义组成,如同C.1静态语境构件描述的那样。

2.6.2 Static Typing Feature

2.6.2 静态类型特征

[Definition: 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).] However, non-type-related static errors (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) must be detected and raised during the static analysis phase (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis).
[定义:一个不支持静态类型特征的XQuery实现不要求在静态分析阶段 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis)引发类型错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error)。]然而,在静态分析阶段 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis),非类型相关的静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)必须要被发现和引发。

2.6.3 Full Axis Feature

2.6.3 全轴特征

[Definition: The following axes are designated as optional axes: ancestor, ancestor-or-self, following, following-sibling, preceding, and preceding-sibling.]
[定义:下列轴指定为可选轴:ancestor,ancestor-or-self,following,following-sibling,preceding和preceding-sibling。]
[Definition: 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).] For an XQuery implementation that does not support the Full Axis Feature, the set of optional axes that are supported is implementation-defined (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-defined). If an implementation encounters a reference to an optional axis that it does not support, it must raise a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error). [err:XQ0010 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXQ0010)]
[定义:一个支持全轴特征的XQuery实现必须支持所有可选轴 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-optional-axis)。]对于一个不支持全轴特征的XQuery实现,它所支持的可选轴集是实现定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-defined)的。如果一个实现遇到一个对它不支持的可选轴的引用,它必须引发一个静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)。[err:XQ0010 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXQ0010)]
Note that XQuery does not recognize the namespace axis (defined by XPath 1.0 and deprecated by XPath 2.0).
注意XQuery不承认namespace 轴(它由XPath 1.0定义,但被XPath 2.0反对。)

2.6.4 Module Feature

2.6.4 模块特征

An XQuery implementation that does not support the Module Feature raises a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) [err:XQ0016 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXQ0016)] 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). Since a module declaration (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-module-declaration) is required in a library module (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-library-module), the Module Feature is required in order to create a library module (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-library-module). In the absence of this feature, each query consists of a single main module (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-main-module).
一个不支持模块特征的XQuery实现如果遇到一个模块声明 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-module-declaration)或一个模块导入 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-module-import)就会引发一个静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)[err:XQ0016 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXQ0016)]。因为模块声明 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-module-declaration)库模块 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-library-module)中是必需的,所以为了创建一个库模块 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-library-module)模块特征是必需的。如果没有这个特征,每个查询由单个主模块 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-main-module)组成。

2.6.5 Pragmas

2.6.5 附注

[Definition: A pragma may be used to provide additional information to an XQuery implementation.] The use of a pragma does not negate the requirement to support normal XQuery functionality in the absence of the pragma.
[定义:一个附注可以用来给一个XQuery实现提供附加信息。]附注的使用不能排除在没有附注时支持正常XQuery功能的需要。





[146]   

Pragma (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-Pragma)

   ::=   

"(::" S (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-S)? "pragma" S (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-S) QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-QName) (S (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-S) ExtensionContents (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ExtensionContents))? "::)"

[148]   

ExtensionContents (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-ExtensionContents)

   ::=   

(Char (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-Char)* - (Char* '::)' Char*))

The QName of a Pragma must contain an explicit namespace prefix. Within a Pragma, the character content may consist of any sequence of characters that does not include the sequence "::)". Pragmas may be used anywhere that ignorable whitespace (http://www.w3.org/TR/2004/WD-xquery-20040723/#IgnorableWhitespace) is allowed. See A.2 Lexical structure for the exact lexical states where pragmas are recognized. A pragma is identified by its QName.
一个附注的QName包含一个显式的命名空间前缀。在一个附注里,字符内容可以有任意字符序列组成,其中不含序列“::)”。附注可以用于任何允许出现可忽略的空白符 (http://www.w3.org/TR/2004/WD-xquery-20040723/#IgnorableWhitespace)的地方。关于能识别附注的具体词法状态见A.2词法结构。一个附注是由它的QName标识。
If an implementation does not support a pragma, then that pragma shall be ignored. If an implementation does support a pragma and the implementation determines that the character content is invalid, then a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) is raised.[err:XQ0013 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXQ0013)] Otherwise, the effect of the pragma on the result of the Query is implementation-defined (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-defined).
如果一个实现不支持附注 ,那么该附注应该被忽略。如果一个实现确实支持附注,并且该实现认为字符内容是无效的,则会引发一个静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)。[err:XQ0013 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXQ0013)] 否则,附注对查询结果的影响是实现定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-defined)的。
The following example shows how a pragma might be used:
下面的例子演示了如何使用一个附注。


declare namespace exq = "http://example.org/XQueryImplementation";

   (:: pragma exq:timeout 1000 ::)
fn:count($doc//author)


An implementation that supports the exq:timeout pragma might raise a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) if it is unable to count the authors within 1000 seconds. An implementation that does not support this pragma would execute as long as necessary to count the authors.
一个支持exq:timeout附注的实现如果不能在1000秒里数清author的数目就会引发一个动态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error)。一个不支持该附注的实现可以执行任意长时间来数清author的数目。

2.6.6 Must-Understand Extensions

2.6.6 必须理解的扩展

[Definition: 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.]
[定义:一个实现可以通过提供必须理解的扩展来扩展XQuery的功能。一个必须理解的扩展可以用于任何可以出现可忽略的空白符 (http://www.w3.org/TR/2004/WD-xquery-20040723/#IgnorableWhitespace)的地方。]





[147]   

MUExtension (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-MUExtension)

   ::=   

"(::" S (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-S)? "extension" S (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-S) QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-QName) (S (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-S) ExtensionContents (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ExtensionContents))? "::)"

[148]   

ExtensionContents (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-ExtensionContents)

   ::=   

(Char (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-Char)* - (Char* '::)' Char*))

A must-understand extension is identified by its QName, which must contain an explicit namespace prefix. The character content may consist of any sequence of characters that does not include the sequence "::)". See A.2 Lexical structure for the exact lexical states where these extensions are recognized.
一个必须理解的扩展由它的QName标识,该QName必须包含一个显式的命名空间前缀。字符内容可以有任意字符序列组成,其中不含序列“::)”。关于能识别这些扩展的具体词法状态见A.2词法结构
If an implementation does not support a must-understand extension, then a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) is raised.[err:XQ0014 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXQ0014)] If an implementation does support a must-understand extension and the implementation determines that the character content is invalid, then a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) is raised. Otherwise, the effect of the must-understand extension on the result of the Query is implementation-defined (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-defined).
如果一个实现不支持一个必须理解的扩展,就会引发一个静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)。[err:XQ0014 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXQ0014)]如果一个实现确实支持一个必须理解的扩展,并且该实现认为字符内容是无效的,那么就会引发一个静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)。否则,必须理解的扩展对查询结果的影响就是实现定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-defined)的。
The following example shows how a must-understand extension might be used:
如下的例子演示了如何使用一个必须理解的扩展:


   declare namespace exq = "http://example.org/XQueryImplementation";
   for $e in fn:doc("employees.xml")//employee
order by $e/lastname (:: extension exq:RightToLeft ::)
return $e


An implementation that supports the exq:RightToLeft extension might order the last names by examining characters from right to left instead of from left to right. An implementation that does not support this extension would raise a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error).
一个支持exq:RightToLeft的扩展可以从右到左而不是从左到右地比较字符来排序这些lastname。一个不支持这个扩展的实现会引发一个静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)

2.6.6.1 XQuery Flagger
2.6.6.1 XQuery标记器



[Definition: 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.] The XQuery Flagger is disabled by default; the mechanism by which the XQuery Flagger is enabled is implementation-defined (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-defined). If the XQuery Flagger is enabled, a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) [err:XQ0015 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXQ0015)] is raised if the query contains a must-understand extension.
[定义:一个XQuery标记器是实现提供的一个功能,它能识别包含了必须理解的扩展 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-must-understand)的查询。如果一个实现支持必须理解的扩展,那么就必须提供XQuery标记器。]缺省情况下XQuery标志器是无效的;XQuery标志器启动的机制是实现定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-defined)的。如果XQuery标志器启动了,而且查询包含了一个必须理解的扩展就会引发一个静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)。[err:XQ0015 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXQ0015)] An XQuery Flagger is provided to assist programmers in producing queries that are portable among multiple conforming XQuery implementations.
一个XQuery标志器是为了帮助程序员产生可以在多个相容的XQuery实现上移植的查询。
The following example illustrates how an XQuery Flagger might be used:
下面的例子演示了如何使用XQuery标志器:


xquery RightToLeft.xquery -Flagger=on


If RightToLeft.xquery contains a must-understand extension such as exq:RightToLeft, then this XQuery invocation will result in a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error). If the XQuery Flagger was not enabled and the implementation supports exq:RightToLeft, then this query might execute without error.
如果RightToLeft.xquery包含了一个必须理解的扩展如exq:RightToLeft,那么这个XQuery的请求会导致一个静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)。如果XQuery标志器没有启动而实现又支持exq:RightToLeft,那么这个查询可能会无错地执行。

2.6.7 Static Typing Extensions

2.6.7 静态类型扩展

In some cases, the static typing rules defined in [XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)] are not very precise (see, for instance, the type inference rules for the ancestor axes—parent, ancestor, and ancestor-or-self—and for the function fn:root). Some implementations may wish to support more precise static typing rules.
在某些情况下,[XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)]中定义的静态类型规则不是很精确(例如,祖先轴——parent,ancestor和ancestor-or-self和函数 fn:root的类型推理规则)。某些实现可能希望支持更精确的静态类型规则。
A conforming implementation may provide a static typing extension. [Definition: 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)].] That is, given an expression E, and its static type T 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)], an implementation may infer a static type T1 for E such that T1 is a subtype of T (that is, all instances of T1 are also instances of T).
一个兼容的实现可以提供一个静态类型扩展。[定义:一个静态类型扩展是一个类型推理规则,它能比[XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)]中的推导规则推导出更精确的静态类型。]也就是说,给定表达式E,和[XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)]中的推导规则推导出的静态类型T,一个实现可以为E推导出一个静态类型T1,使得T1T的子类型(也就是说,所有T1的实例同时也是T的实例)。
Note:
注意:
It is not recommended for a static typing extension to change the static type behavior of the treat expression, since static type behavior is central to the semantics of this expression.
我们并不建议一个静态类型扩展去改变treat表达式的静态类型行为,因为静态类型行为是这个表达式的语义的核心。

2.6.7.1 XQuery Static Flagger
2.6.7.1 XQuery静态标记器



[Definition: 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).] If an implementation supports static typing extensions, then it must also provide an XQuery Static Flagger. The XQuery Static Flagger is disabled by default; the mechanism by which it is enabled is implementation-defined (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-defined). When enabled, the XQuery Static Flagger must raise a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) during the static analysis phase (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis) wherever a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) is called for by the rules in [XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)]. The purpose of an XQuery Static Flagger is to assist programmers in producing queries that are portable among multiple conforming XQuery implementations.
[定义:一个XQuery静态标志器是一项能识别那些需要静态类型扩展 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-typing-extension)的查询的功能。]如果一个实现支持静态类型扩展,那么它也必须提供一个XQuery静态标志器。缺省情况下,XQuery静态标志器是无效的;启动它的机制是实现定义 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-defined)的。当XQuery标志器启动后,在静态分析阶段 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-analysis)只要 [XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)] 中的规则调用了一个类型错误,该XQuery静态标志器就会引发一个静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)。XQuery静态标志器的目的是为了帮助程序员产生可以在多个相容的XQuery实现之间移植的查询。
The following example illustrates how an XQuery Static Flagger might be used:
下面的例子演示了可以如何使用一个XQuery静态标志器:


xquery abc.xquery -StaticFlagger=on


If abc.xquery contains a type error according to the static semantic rules in [XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)], then this XQuery invocation will result in a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error). If the XQuery Static Flagger was not enabled and the implementation supports a static typing extension (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-typing-extension), then this query might execute without error.
如果根据[XQuery 1.0 and XPath 2.0 Formal Semantics (http://www.w3.org/TR/2004/WD-xquery-20040723/#XQueryFormalSemantics)]中的静态语义规则,abc.xquery包含了一个类型错误,那么这个XQuery的请求会导致一个静态错误 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error)。如果该XQuery静态标志器没有启动而且实现支持一个静态类型扩展 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-typing-extension),那么这个查询可能会无错地执行。

2.7 Comments

2.7 注释





[149]   

Comment (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-Comment)

   ::=   

"(:" (CommentContents (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-CommentContents) | Comment (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-Comment))* ":)"

[150]   

CommentContents (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-CommentContents)

   ::=   

(Char (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-Char)+ - (Char* ':)' Char*))

Comments may be used to provide informative annotation for a query, either in the Prolog (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-prolog) or in the Query Body (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-queryBody). Comments are lexical constructs only, and do not affect query processing.
注释可以用来为一个查询提供带有相关信息的注解,或者在 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-prolog)里,或者在查询体 (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-queryBody)里。注释仅仅是词法上的构造物,不会影响查询的处理。
Comments are strings, delimited by the symbols (: and :). Comments may be nested.
注释是由(:和:)定界的字符串。注释可以嵌套。
A comment may be used anywhere ignorable whitespace (http://www.w3.org/TR/2004/WD-xquery-20040723/#IgnorableWhitespace) is allowed. See A.2 Lexical structure for the exact lexical states where comments are recognized.
凡是可忽略的空白符 (http://www.w3.org/TR/2004/WD-xquery-20040723/#IgnorableWhitespace)可以出现的地方都可以使用注释。关于识别注释的具体词法状态见A.2词法结构
The following is an example of a comment:
下面是一个注释的例子:


(: Houston, we have a problem :)


Other languages
 
 Page execution time: 3424.72 ms.
网上报警 苏ICP备05002329号 苏ICP备05006046号