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
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)定义的。

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