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

TransWiki - W3CHINA.ORG开放翻译计划(OTP)

摘要_文档状态_目录 第1节 第2节 3.1~3.3节 3.4~3.6节 3.7节 3.8~3.13节 第4节 附录A 附录B,C,D 附录E,F,G,H,I


目录

3 Expressions

This section discusses each of the basic kinds of expression. Each kind of expression has a name such as PathExpr, which is introduced on the left side of the grammar production that defines the expression. Since XQuery is a composable language, each kind of expression is defined in terms of other expressions whose operators have a higher precedence. In this way, the precedence of operators is represented explicitly in the grammar.
The order in which expressions are discussed in this document does not reflect the order of operator precedence. In general, this document introduces the simplest kinds of expressions first, followed by more complex expressions. For the complete grammar, see Appendix [A XQuery Grammar].




[26]    Expr (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-Expr)    ::=    ExprSingle (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ExprSingle) ("," ExprSingle (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ExprSingle))*
[27]    ExprSingle (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-ExprSingle)    ::=   

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

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

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

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

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

A query may consist of one or more modules, as described in 4 Modules and Prologs. If a query is executable, one of its modules has a Query Body (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-queryBody) containing an expression whose value is the result of the query. An expression is represented in the XQuery grammar by the symbol Expr.
The XQuery operator that has lowest precedence is the comma operator (described in 3.3.1 Constructing Sequences), which is used to combine two operands to form a sequence. As shown in the grammar, a general expression (Expr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-Expr)) can consist of two operands (ExprSingle (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ExprSingle)) separated by a comma. The name ExprSingle (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ExprSingle) denotes an expression that does not contain a top-level comma operator (despite its name, an ExprSingle (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ExprSingle) may evaluate to a sequence containing more than one item.)
The symbol ExprSingle (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ExprSingle) is used in various places in the grammar where an expression is not allowed to contain a top-level comma. For example, each of the arguments of a function call must be an ExprSingle (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ExprSingle), because commas are used to separate the arguments of a function call.
After the comma, the expressions that have next lowest precedence are FLWORExpr, QuantifiedExpr, TypeswitchExpr, IfExpr, and OrExpr. Each of these expressions is described in a separate section of this document.

3.1 Primary Expressions

[Definition: Primary expressions are the basic primitives of the language. They include literals, variable references, context item expressions, constructors, and function calls. A primary expression may also be created by enclosing any expression in parentheses, which is sometimes helpful in controlling the precedence of operators.] Constructors are described in 3.7 Constructors.



[75]    PrimaryExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-PrimaryExpr)    ::=    Literal (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-Literal) | VarRef (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-VarRef) | ParenthesizedExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ParenthesizedExpr) | ContextItemExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ContextItemExpr) | FunctionCall (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-FunctionCall) | Constructor (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-Constructor) | OrderedExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-OrderedExpr) | UnorderedExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-UnorderedExpr)

3.1.1 Literals

[Definition: A literal is a direct syntactic representation of an atomic value.] XQuery supports two kinds of literals: numeric literals and string literals.










[76]    Literal (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-Literal)    ::=    NumericLiteral (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-NumericLiteral) | StringLiteral (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-StringLiteral)
[77]    NumericLiteral (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-NumericLiteral)    ::=    IntegerLiteral (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-IntegerLiteral) | DecimalLiteral (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-DecimalLiteral) | DoubleLiteral (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-DoubleLiteral)
[131]    IntegerLiteral (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-IntegerLiteral)    ::=    Digits (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-Digits)
[132]    DecimalLiteral (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-DecimalLiteral)    ::=    ("." Digits (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-Digits)) | (Digits (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-Digits) "." [0-9]*)
[133]    DoubleLiteral (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-DoubleLiteral)    ::=    (("." Digits (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-Digits)) | (Digits (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-Digits) ("." [0-9]*)?)) [eE] [+-]? Digits (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-Digits)
[134]    StringLiteral (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-StringLiteral)    ::=    ('"' (PredefinedEntityRef (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-PredefinedEntityRef) | CharRef (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-CharRef) | ('"' '"') | [^"&])* '"') | ("'" (PredefinedEntityRef (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-PredefinedEntityRef) | CharRef (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-CharRef) | ("'" "'") | [^'&])* "'")
[139]    PredefinedEntityRef (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-PredefinedEntityRef)    ::=    "&" ("lt" | "gt" | "amp" | "quot" | "apos") ";"
[138]    Digits (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-Digits)    ::=    [0-9]+

The value of a numeric literal containing no "." and no e or E character is an atomic value of type xs:integer. The value of a numeric literal containing "." but no e or E character is an atomic value of type xs:decimal. The value of a numeric literal containing an e or E character is an atomic value of type xs:double. Values of numeric literals are interpreted according to the rules in [XML Schema (http://www.w3.org/TR/2004/WD-xquery-20040723/#XMLSchema)].
The value of a string literal is an atomic value whose type is xs:string and whose value is the string denoted by the characters between the delimiting apostrophes or quotation marks. If the literal is delimited by apostrophes, two adjacent apostrophes within the literal are interpreted as a single apostrophe. Similarly, if the literal is delimited by quotation marks, two adjacent quotation marks within the literal are interpreted as one quotation mark.
A string literal may contain a predefined entity reference, which is a short sequence of characters, beginning with an ampersand, that represents a single character that might otherwise have syntactic significance. Each predefined entity reference is replaced by the character it represents when the string literal is processed. The predefined entity references recognized by XQuery are as follows:









Entity Reference

Character Represented

<

<

&gt;

>

&amp;

&

&quot;

"

&apos;

'

A string literal may also contain a character reference, which is an XML-style reference to a Unicode character, identified by its decimal or hexadecimal code point. For example, the Euro symbol (€) can be represented by the character reference &#8364;. Character references are formally defined in Section 4.1 of [XML 1.0 (http://www.w3.org/TR/2004/WD-xquery-20040723/#XML)] or [XML 1.1 (http://www.w3.org/TR/2004/WD-xquery-20040723/#XML1.1)] (which definition applies is implementation-defined (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-defined)).
Here are some examples of literal expressions:


"12.5" denotes the string containing the characters '1', '2', '.', and '5'.


12 denotes the integer value twelve.


12.5 denotes the decimal value twelve and one half.


125E2 denotes the double value twelve thousand, five hundred.


"He said, ""I don't like it.""" denotes a string containing two quotation marks and one apostrophe.


"Ben &amp; Jerry&apos;s" denotes the string "Ben & Jerry's".


"&#8364;99.50" denotes the string "€99.50".
The boolean values true and false can be represented by calls to the built-in functions fn:true() and fn:false(), respectively.
Values of other atomic types can be constructed by calling the constructor for the given type. The constructors for XML Schema built-in types are defined in [XQuery 1.0 and XPath 2.0 Functions and Operators (http://www.w3.org/TR/2004/WD-xquery-20040723/#FunctionsAndOperators)]. In general, the name of a constructor function for a given type is the same as the name of the type (including its namespace). For example:


xs:integer("12") returns the integer value twelve.


xs:date("2001-08-25") returns an item whose type is xs:date and whose value represents the date 25th August 2001.


xdt:dayTimeDuration("PT5H") returns an item whose type is xdt:dayTimeDuration and whose value represents a duration of five hours.
It is also possible to construct values of various types by using a cast expression. For example:


9 cast as hatsize returns the atomic value 9 whose type is hatsize.

3.1.2 Variable References




[78]    VarRef (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-VarRef)    ::=    "$" VarName (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-VarName)
[136]    VarName (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-VarName)    ::=    QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-QName)

A variable reference is a QName preceded by a $-sign. Two variable references are equivalent if their local names are the same and their namespace prefixes are bound to the same namespace URI in the statically known namespaces (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-namespaces). An unprefixed variable reference is in no namespace.
Every variable reference must match a name in the in-scope variables (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-in-scope-variables), which include variables from the following sources:


A variable may be declared in a Prolog (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-prolog), in the current module (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-module) or an imported module. See 4 Modules and Prologs for a discussion of modules and Prologs.


A variable may be added to the in-scope variables (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-in-scope-variables) by the host language environment.


A variable may be bound by an XQuery expression. The kinds of expressions that can bind variables are FLWOR expressions (3.8 FLWOR Expressions), quantified expressions (3.11 Quantified Expressions), and typeswitch expressions (3.12.2 Typeswitch). Function calls also bind values to the formal parameters of functions before executing the function body.
Every variable binding has a static scope. The scope defines where references to the variable can validly occur. It is 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)] to reference a variable that is not in scope. If a variable is bound in the static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context) for an expression, that variable is in scope for the entire expression.
If a variable reference matches two or more variable bindings that are in scope, then the reference is taken as referring to the inner binding, that is, the one whose scope is smaller. At evaluation time, the value of a variable reference is the value of the expression to which the relevant variable is bound. The scope of a variable binding is defined separately for each kind of expression that can bind variables.

3.1.3 Parenthesized Expressions



[79]    ParenthesizedExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-ParenthesizedExpr)    ::=    "(" Expr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-Expr)? ")"

Parentheses may be used to enforce a particular evaluation order in expressions that contain multiple operators. For example, the expression (2 + 4) * 5 evaluates to thirty, since the parenthesized expression (2 + 4) is evaluated first and its result is multiplied by five. Without parentheses, the expression 2 + 4 * 5 evaluates to twenty-two, because the multiplication operator has higher precedence than the addition operator.
Empty parentheses are used to denote an empty sequence, as described in 3.3.1 Constructing Sequences.

3.1.4 Context Item Expression



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

A context item expression evaluates to the context item (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-context-item), which may be either a node (as in the expression fn:doc("bib.xml")//book[fn:count(./author)>1]) or an atomic value (as in the expression (1 to 100)[. mod 5 eq 0]).
If the context item (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-context-item) is undefined, a context item expression raises a dynamic error.[err:XP0002 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0002)]

3.1.5 Function Calls

A function call consists of a QName followed by a parenthesized list of zero or more expressions, called arguments. If the QName in the function call has no namespace prefix, it is considered to be in the default function namespace. (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-def-fn-ns)
If the expanded QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-expanded-qname) and number of arguments in a function call do not match the name and arity of a function signature (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-function-signature) in the static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context), a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) is raised.[err:XP0017 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0017)]



[83]    FunctionCall (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-FunctionCall)    ::=    QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-QName) "(" (ExprSingle (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ExprSingle) ("," ExprSingle (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ExprSingle))*)? ")"

XQuery allows functions to be called. A core library of functions is defined in [XQuery 1.0 and XPath 2.0 Functions and Operators (http://www.w3.org/TR/2004/WD-xquery-20040723/#FunctionsAndOperators)]. Additional functions may be declared in a Prolog (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-prolog), imported from a library module (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-library-module), or provided by the external environment as part of the static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context). For details on processing function names that have no namespace prefix, see 4.7 Default Namespace Declaration.
A function call is evaluated as follows:


Argument expressions are evaluated, producing argument values. The order of argument evaluation is implementation-dependent (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent) and a function need not evaluate an argument if the function can evaluate its body without evaluating that argument.


Each argument value is converted by applying the function conversion rules listed below.


If the function is a built-in function, it is evaluated using the converted argument values. The result is a value of the function's declared return type.


If the function is a user-declared function, the converted argument values are bound to the formal parameters of the function, and the function body is evaluated. The value returned by the function body is then converted to the declared return type of the function by applying the function conversion rules.
When a converted argument value is bound to a function parameter, the argument value retains its most specific dynamic type, even though this may be a subtype of the type of the formal parameter. For example, a function with a parameter $p of type xs:decimal can be invoked with an argument of type xs:integer, which is derived from xs:decimal. During the processing of this function invocation, the dynamic type of $p inside the body of the function is considered to be xs:integer. Similarly, the value returned by a function retains its most specific type, which may be a subtype of the declared return type of the function. For example, a function that has a declared return type of xs:decimal may in fact return a value of dynamic type xs:integer.
During execution of a function body, the static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context) and dynamic context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-context) for expression evaluation are defined by the module resource (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-module-resource) in which the function is declared, which is not necessarily the same as the module resource (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-module-resource) in which the function is called. As an example of this rule, a function does not inherit a focus (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-focus) (context item, context position, and context size) from the calling environment. During evaluation of a function body, the focus is undefined, except where it is defined by the action of some expression inside the function body. It is a static error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-error) [err:XP0018 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0018)] for an expression to depend on the focus when the focus is undefined.
The function conversion rules are used to convert an argument value or a return value to its expected type; that is, to the declared type of the function parameteror return. The expected type is expressed as a SequenceType (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-sequence-type). The function conversion rules are applied to a given value as follows:


If the expected type is a sequence of an atomic type (possibly with an occurrence indicator *, +, or ?), the following conversions are applied:


Atomization (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-atomization) is applied to the given value, resulting in a sequence of atomic values.


Each item in the atomic sequence that is of type xdt:untypedAtomic is cast to the expected atomic type. For built-in functions where the expected type is specified as numeric, arguments of type xdt:untypedAtomic are cast to xs:double.


For each numeric item in the atomic sequence that can be promoted (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-promotion) to the expected atomic type using the promotion rules in B.1 Type Promotion, the promotion is done.


If, after the above conversions, the resulting value does not match the expected type according to the rules for SequenceType Matching (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-sequencetype-matching), 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)][err:XP0006 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0006)] If the function call takes place in a module resource (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-module-resource) other than the module resource (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-module-resource) in which the function is defined, this rule must be satisfied in both the module resource where the function is called and the module resource where the function is defined (the test is repeated because the two module resources may have different in-scope schema definitions (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-issd).) Note that the rules for SequenceType Matching (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-sequencetype-matching) permit a value of a derived type to be substituted for a value of its base type.
Since the arguments of a function call are separated by commas, any argument expression that contains a top-level comma operator must be enclosed in parentheses. Here are some illustrative examples of function calls:


my:three-argument-function(1, 2, 3) denotes a function call with three arguments.


my:two-argument-function((1, 2), 3) denotes a function call with two arguments, the first of which is a sequence of two values.


my:two-argument-function(1, ()) denotes a function call with two arguments, the second of which is an empty sequence.


my:one-argument-function((1, 2, 3)) denotes a function call with one argument that is a sequence of three values.


my:one-argument-function(( )) denotes a function call with one argument that is an empty sequence.


my:zero-argument-function( ) denotes a function call with zero arguments.

3.2 Path Expressions

A path expression can be used to locate nodes within trees.




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

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

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

| RelativePathExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-RelativePathExpr)
[60]    RelativePathExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-RelativePathExpr)    ::=    StepExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-StepExpr) (("/" | "//") StepExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-StepExpr))*

A path expression consists of a series of one or more steps, separated by "/" or "//", and optionally beginning with "/" or "//". An initial "/" or "//" is an abbreviation for one or more initial steps that are implicitly added to the beginning of the path expression, as described below.
A path expression consisting of a single step is evaluated as described in 3.2.1 Steps.
Each occurrence of "//" in a path expression is expanded as described in 3.2.4 Abbreviated Syntax, leaving a sequence of steps separated by "/". This sequence of steps is then evaluated from left to right. Each operation E1/E2 is evaluated as follows: Expression E1 is evaluated, and if the result is not a (possibly empty) sequence of nodes, a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) is raised.[err:XP0019 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0019)] Each node resulting from the evaluation of E1 then serves in turn to provide an inner focus for an evaluation of E2, as described in 2.1.2 Dynamic Context. Each evaluation of E2 must result in a (possibly empty) sequence of nodes; otherwise, a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) is raised.[err:XP0019 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0019)] The sequences of nodes resulting from all the evaluations of E2 are combined, and duplicate nodes are eliminated based on node identity. If ordering mode (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-ordering-mode) is ordered, the resulting node sequence is returned in document order (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-document-order); otherwise it is returned in implementation-dependent (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent) order.
As an example of a path expression, child::div1/child::para selects the para element children of the div1 element children of the context node, or, in other words, the para element grandchildren of the context node that have div1 parents.
A "/" at the beginning of a path expression is an abbreviation for the initial step fn:root(self::node()) treat as document-node() (this is true even if the "/" is the entire path expression). The effect of this initial step is to begin the path at the root node of the tree that contains the context node. If the context item is not a node, a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) is raised.[err:XP0020 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0020)] At evaluation time, if the root node above the context node is not a document node, a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) is raised.[err:XP0050 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0050)]
A "//" at the beginning of a path expression is an abbreviation for the initial steps fn:root(self::node()) treat as document-node()/descendant-or-self::node(). The effect of these initial steps is to establish an initial node sequence that contains the root of the tree in which the context node is found, plus all nodes descended from this root. This node sequence is used as the input to subsequent steps in the path expression. If the context item is not a node, a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) is raised.[err:XP0020 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0020)] At evaluation time, if the root node above the context node is not a document node, a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) is raised.[err:XP0050 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0050)]
Note:
The descendants of a node do not include attribute nodes.
Note:
The "/" character can be used either as an individual token or as part of a pattern such as "/*". This can cause parsing difficulties when "/" appears on the left hand side of an operator. For example, "/*" is a valid path expression with a wildcard, but "/*5" and "/ * 5" raise parsing errors. Parentheses must be used when "/" is used as the first operand of an operator, as in "(/) * 5". Similarly, "4 + / * 5" raises a parsing error, but "4 + (/) * 5" is a valid expression. The expression 4 + /" is also valid, because / does not occur on the left hand side of the operator.

3.2.1 Steps







[61]    StepExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-StepExpr)    ::=    AxisStep (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AxisStep) | FilterExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-FilterExpr)
[62]    AxisStep (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-AxisStep)    ::=    (ForwardStep (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ForwardStep) | ReverseStep (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ReverseStep)) PredicateList (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-PredicateList)
[63]    ForwardStep (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-ForwardStep)    ::=    (ForwardAxis (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ForwardAxis) NodeTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-NodeTest)) | AbbrevForwardStep (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AbbrevForwardStep)
[66]    ReverseStep (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-ReverseStep)    ::=    (ReverseAxis (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ReverseAxis) NodeTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-NodeTest)) | AbbrevReverseStep (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AbbrevReverseStep)
[73]    PredicateList (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-PredicateList)    ::=    Predicate (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-Predicate)*

A step generates a sequence of items and then filters the sequence by zero or more predicates. The value of the step consists of those items that satisfy the predicates. Predicates are described in 3.2.2 Predicates. A step may be either an axis step or a filter expression. Filter expressions are described in 3.3.2 Filter Expressions.
The result of an axis step is always a sequence of zero or more nodes, and these nodes are always returned in document order (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-document-order). An axis step may be either a forward step or a reverse step, followed by zero or more predicates. An axis step might be thought of as beginning at the context node and navigating to those nodes that are reachable from the context node via a specified axis. Such a step has two parts: an axis, which defines the "direction of movement" for the step, and a node test (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-node-test), which selects nodes based on their kind, name, and/or type. If the context item is not a node, a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) is raised.[err:XP0020 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0020)]
In the abbreviated syntax for a step, the axis can be omitted and other shorthand notations can be used as described in 3.2.4 Abbreviated Syntax.
The unabbreviated syntax for an axis step consists of the axis name and node test separated by a double colon. The result of the step consists of the nodes reachable from the context node via the specified axis that have the node kind, name, and/or type specified by the node test. For example, the step child::para selects the para element children of the context node: child is the name of the axis, and para is the name of the element nodes to be selected on this axis. The available axes are described in 3.2.1.1 Axes. The available node tests are described in 3.2.1.2 Node Tests. Examples of steps are provided in 3.2.3 Unabbreviated Syntax and 3.2.4 Abbreviated Syntax.

3.2.1.1 Axes




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

("child" "::")

| ("descendant" "::")

| ("attribute" "::")

| ("self" "::")

| ("descendant-or-self" "::")

| ("following-sibling" "::")

| ("following" "::")
[67]    ReverseAxis (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-ReverseAxis)    ::=   

("parent" "::")

| ("ancestor" "::")

| ("preceding-sibling" "::")

| ("preceding" "::")

| ("ancestor-or-self" "::")

XQuery supports the following axes (subject to limitations as described in 2.6.3 Full Axis Feature):


The child axis contains the children of the context node, which are the nodes returned by the dm:children accessor in [XQuery 1.0 and XPath 2.0 Data Model (http://www.w3.org/TR/2004/WD-xquery-20040723/#datamodel)].
Note:
Only document nodes and element nodes have children. If the context node is any other kind of node, or if the context node is an empty document or element node, then the child axis is an empty sequence. The children of a document node or element node may be element, processing instruction, comment, or text nodes. Attribute and document nodes can never appear as children.


the descendant axis is defined as the transitive closure of the child axis; it contains the descendants of the context node (the children, the children of the children, and so on)


the parent axis contains the sequence returned by the dm:parent accessor in [XQuery 1.0 and XPath 2.0 Data Model (http://www.w3.org/TR/2004/WD-xquery-20040723/#datamodel)], which returns the parent of the context node, or an empty sequence if the context node has no parent


the ancestor axis is defined as the transitive closure of the parent axis; it contains the ancestors of the context node (the parent, the parent of the parent, and so on)
Note:
The ancestor axis includes the root node of the tree in which the context node is found, unless the context node is the root node.


the following-sibling axis contains the context node's following siblings, those children of the context node's parent that occur after the context node in document order (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-document-order); if the context node is an attribute node, the following-sibling axis is empty


the preceding-sibling axis contains the context node's preceding siblings, those children of the context node's parent that occur before the context node in document order (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-document-order); if the context node is an attribute node, the preceding-sibling axis is empty


the following axis contains all nodes that are descendants of the root of the tree in which the context node is found, are not descendants of the context node, and occur after the context node in document order (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-document-order)


the preceding axis contains all nodes that are descendants of the root of the tree in which the context node is found, are not ancestors of the context node, and occur before the context node in document order (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-document-order)


the attribute axis contains the attributes of the context node, which are the nodes returned by the dm:attributes accessor in [XQuery 1.0 and XPath 2.0 Data Model (http://www.w3.org/TR/2004/WD-xquery-20040723/#datamodel)]; the axis will be empty unless the context node is an element


the self axis contains just the context node itself


the descendant-or-self axis contains the context node and the descendants of the context node


the ancestor-or-self axis contains the context node and the ancestors of the context node; thus, the ancestor-or-self axis will always include the root node
Axes can be categorized as forward axes and reverse axes. An axis that only ever contains the context node or nodes that are after the context node in document order (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-document-order) is a forward axis. An axis that only ever contains the context node or nodes that are before the context node in document order (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-document-order) is a reverse axis.
The parent, ancestor, ancestor-or-self, preceding, and preceding-sibling axes are reverse axes; all other axes are forward axes. The ancestor, descendant, following, preceding and self axes partition a document (ignoring attribute nodes): they do not overlap and together they contain all the nodes in the document.
In a sequence of nodes selected by an axis step, each node is assigned a context position that corresponds to its position in the sequence. If the axis is a forward axis, context positions are assigned to the nodes in document order (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-document-order), starting with 1. If the axis is a reverse axis, context positions are assigned to the nodes in reverse document order (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-reverse-document-order), starting with 1. This makes it possible to select a node from the sequence by specifying its position.
Note:
One example of an expression that uses the context position is a numeric predicate. The expression child::para[1] selects the first para element that is a child of the context node.

3.2.1.2 Node Tests



[Definition: A node test is a condition that must be true for each node selected by a step.] The condition may be based on the kind of the node (element, attribute, text, document, comment, or processing instruction), the name of the node, or (in the case of element, attribute, and document nodes), the type of the node.





[69]    NodeTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-NodeTest)    ::=    KindTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-KindTest) | NameTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-NameTest)
[70]    NameTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-NameTest)    ::=    QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-QName) | Wildcard (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-Wildcard)
[71]    Wildcard (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-Wildcard)    ::=   

"*"

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

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

[Definition: Every axis has a principal node kind. If an axis can contain elements, then the principal node kind is element; otherwise, it is the kind of nodes that the axis can contain.] Thus:


For the attribute axis, the principal node kind is attribute.


For all other axes, the principal node kind is element.
[Definition: A node test that consists only of a QName or a Wildcard is called a name test.] A name test is true if and only if the kind of the node is the principal node kind (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-principal-node-kind) and the expanded QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-expanded-qname) of the node is equal (on a codepoint basis) to the expanded QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-expanded-qname) specified by the name test. For example, child::para selects the para element children of the context node; if the context node has no para children, it selects an empty set of nodes. attribute::abc:href selects the attribute of the context node with the QName abc:href; if the context node has no such attribute, it selects an empty set of nodes.
A QName in a name test is resolved into an expanded QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-expanded-qname) using the statically known namespaces (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-namespaces) in the expression context. It is 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)] if the QName has a prefix that does not correspond to any statically known namespace. An unprefixed QName, when used as a name test on an axis whose principal node kind (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-principal-node-kind) is element, has the namespace URI of the default element/type namespace (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-def-elemtype-ns) in the expression context; otherwise, it has no namespace URI.
A name test is not satisfied by an element node whose name does not match the QName of the name test, even if it is in a substitution group (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-substitution-group) whose head is the named element.
A node test * is true for any node of the principal node kind (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-principal-node-kind). For example, child::* will select all element children of the context node, and attribute::* will select all attributes of the context node.
A node test can have the form NCName:*. In this case, the prefix is expanded in the same way as with a QName, using the statically known namespaces (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-namespaces) in the static context (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-static-context). If the prefix is not found in the statically known namespaces, 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)] The node test is true for any node of the principal node kind (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-principal-node-kind) whose expanded QName (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-expanded-qname) has the namespace URI to which the prefix is bound, regardless of the local part of the name.
A node test can also have the form *:NCName. In this case, the node test is true for any node of the principal node kind (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-principal-node-kind) whose local name matches the given NCName, regardless of its namespace.
[Definition: An alternative form of a node test called a kind test can select nodes based on their kind, name, and type annotation.] The syntax and semantics of a kind test are described in 2.4 Types. When a kind test is used in a node test (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-node-test), only those nodes on the designated axis that match the kind test are selected. Shown below are several examples of kind tests that might be used in path expressions:


node() matches any node.


text() matches any text node.


comment() matches any comment node.


element() matches any element node.


element(person) matches any element node whose name is person (or is in the substitution group (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-substitution-group) headed by person), and whose type annotation conforms to the top-level element declaration for a person element.


element(person, *) matches any element node whose name is person (or is in the substitution group (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-substitution-group) headed by person), without any restriction on type annotation.


element(person, surgeon) matches any element node whose name is person (or is in the substitution group (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-substitution-group) headed by person), and whose type annotation is surgeon.


element(*, surgeon) matches any element node whose type annotation is surgeon, regardless of its name.


element(hospital/staff/person) matches any element node whose name and type annotation conform to the schema declaration of a person element in a staff element in a hospital element whose declaration is a top-level element declaration.


attribute() matches any attribute node.


attribute(price, *) matches any attribute whose name is price, regardless of its type annotation.


attribute(*, xs:decimal) matches any attribute whose type annotation is xs:decimal, regardless of its name.


document-node() matches any document node.


document-node(element(book)) matches any document node whose content consists of a single element node that satisfies the kind test (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-kind-test) element(book), mixed with zero or more comments and processing instructions.

3.2.2 Predicates



[74]    Predicate (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-Predicate)    ::=    "[" Expr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-Expr) "]"

A predicate consists of an expression, called a predicate expression, enclosed in square brackets. A predicate serves to filter a sequence, retaining some items and discarding others. For each item in the sequence to be filtered, the predicate expression is evaluated using an inner focus derived from that item, as described in 2.1.2 Dynamic Context. The result of the predicate expression is coerced to a xs:boolean value, called the predicate truth value, as described below. Those items for which the predicate truth value is true are retained, and those for which the predicate truth value is false are discarded.
The predicate truth value is derived by applying the following rules, in order:


If the value of the predicate expression is an atomic value of a numeric type, the predicate truth value is true if the value of the predicate expression is equal (by the eq operator) to the context position, and is false otherwise.


Otherwise, the predicate truth value is the effective boolean value (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-ebv) of the predicate expression.
Here are some examples of axis steps that contain predicates:


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


child::chapter[2]



This example selects all the descendants of the context node that are elements named "toy" and whose color attribute has the value "red":


descendant::toy[attribute::color = "red"]



This example selects all the employee children of the context node that have a secretary child element:


child::employee[secretary]


When using predicates with a sequence of nodes selected using a reverse axis, it is important to remember that the the context positions for such a sequence are assigned in reverse document order (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-reverse-document-order). For example, preceding::foo[1] returns the first qualifying foo element in reverse document order (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-reverse-document-order), because the predicate is part of an axis step using a reverse axis. By contrast, (preceding::foo)[1] returns the first qualifying foo element in document order (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-document-order), because the parentheses cause (preceding::foo) to be parsed as a primary expression (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-primary-expression) in which context positions are assigned in document order. Similarly, ancestor::*[1] returns the nearest ancestor element, because the ancestor axis is a reverse axis, whereas (ancestor::*)[1] returns the root element (first ancestor in document order).

3.2.3 Unabbreviated Syntax

This section provides a number of examples of path expressions in which the axis is explicitly specified in each step. The syntax used in these examples is called the unabbreviated syntax. In many common cases, it is possible to write path expressions more concisely using an abbreviated syntax, as explained in 3.2.4 Abbreviated Syntax.


child::para selects the para element children of the context node


child::* selects all element children of the context node


child::text() selects all text node children of the context node


child::node() selects all the children of the context node, whatever their node type


attribute::name selects the name attribute of the context node


attribute::* selects all the attributes of the context node


parent::node() selects the parent of the context node. If the context node is an attribute node, this expression returns the element node (if any) to which the attribute node is attached.


descendant::para selects the para element descendants of the context node


ancestor::div selects all div ancestors of the context node


ancestor-or-self::div selects the div ancestors of the context node and, if the context node is a div element, the context node as well


descendant-or-self::para selects the para element descendants of the context node and, if the context node is a para element, the context node as well


self::para selects the context node if it is a para element, and otherwise selects nothing


child::chapter/descendant::para selects the para element descendants of the chapter element children of the context node


child::*/child::para selects all para grandchildren of the context node


/ selects the root of the tree that contains the context node, but raises a dynamic error if this root is not a document node


/descendant::para selects all the para elements in the same document as the context node


/descendant::list/child::member selects all the member elements that have a list parent and that are in the same document as the context node


child::para[fn:position() = 1] selects the first para child of the context node


child::para[fn:position() = fn:last()] selects the last para child of the context node


child::para[fn:position() = fn:last()-1] selects the last but one para child of the context node


child::para[fn:position() > 1] selects all the para children of the context node other than the first para child of the context node


following-sibling::chapter[fn:position() = 1]selects the next chapter sibling of the context node


preceding-sibling::chapter[fn:position() = 1]selects the previous chapter sibling of the context node


/descendant::figure[fn:position() = 42] selects the forty-second figure element in the document containing the context node


/child::book/child::chapter[fn:position() = 5]/child::section[fn:position() = 2] selects the second section of the fifth chapter of the book whose parent is the document node that contains the context node


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


child::para[attribute::type='warning'][fn:position() = 5]selects the fifth para child of the context node that has a type attribute with value warning


child::para[fn:position() = 5][attribute::type="warning"]selects the fifth para child of the context node if that child has a type attribute with value warning


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


child::chapter[child::title] selects the chapter children of the context node that have one or more title children


child::*[self::chapter or self::appendix] selects the chapter and appendix children of the context node


child::*[self::chapter or self::appendix][fn:position() = fn:last()] selects the last chapter or appendix child of the context node

3.2.4 Abbreviated Syntax




[65]    AbbrevForwardStep (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-AbbrevForwardStep)    ::=    "@"? NodeTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-NodeTest)
[68]    AbbrevReverseStep (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-AbbrevReverseStep)    ::=    ".."

The abbreviated syntax permits the following abbreviations:


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


If the axis name is omitted from an axis step, the default axis is child unless the axis step contains an AttributeTest (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AttributeTest); in that case, the default axis is attribute. For example, the path expression section/para is an abbreviation for child::section/child::para, and the path expression section/@id is an abbreviation for child::section/attribute::id. Similarly, section/attribute(id) is an abbreviation for child::section/attribute::attribute(id). Note that the latter expression contains both an axis specification and a node test (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-node-test).


// is effectively replaced by /descendant-or-self::node()/ during processing of a path expression. For example, //para is an abbreviation for /descendant-or-self::node()/child::para and so will select any para element in the document (even a para element that is a document element will be selected by //para since the document element node is a child of the root node); div1//para is short for child::div1/descendant-or-self::node()/child::para and so will select all para descendants of div1 children.
Note:
The path expression //para[1] does not mean the same as the path expression /descendant::para[1]. The latter selects the first descendant para element; the former selects all descendant para elements that are the first para children of their respective parents.


A step consisting of .. is short for parent::node(). For example, ../title is short for parent::node()/child::title and so will select the title children of the parent of the context node.
Note:
The expression ., known as a context item expression, is a primary expression (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-primary-expression), and is described in 3.1.4 Context Item Expression.
Here are some examples of path expressions that use the abbreviated syntax:


para selects the para element children of the context node


  • selects all element children of the context node

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


@name selects the name attribute of the context node


@* selects all the attributes of the context node


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


para[fn:last()] selects the last para child of the context node


  • /para selects all para grandchildren of the context node

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


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


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


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


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


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


.. selects the parent of the context node


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


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


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


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


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


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


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


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


If E is any expression that returns a sequence of nodes, then the expression E/. returns the same nodes in document order (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-document-order), with duplicates eliminated based on node identity.

个人工具
其它语言
 
 Page execution time: 1021.68 ms.
网上报警 苏ICP备05002329号