XQuery 1.0:XML查询语言 工作草案-3-1
TransWiki - an Open Translation Project(OTP)
摘要_文档状态_目录 第1节 第2节 3.1~3.3节 3.4~3.6节 3.7节 3.8~3.13节 第4节 附录A 附录B,C,D 附录E,F,G,H,I
| Table of contents |
3.3 Sequence Expressions
XQuery supports operators to construct, filter, and combine sequences (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-sequence) of items (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-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).
3.3.1 Constructing Sequences
| [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))* |
| [44] | RangeExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-RangeExpr) | ::= | AdditiveExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AdditiveExpr) ( "to" AdditiveExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AdditiveExpr) )? |
One way to construct a sequence is by using the comma operator, which evaluates each of its operands and concatenates the resulting values, in order, into a single result sequence.
A sequence may contain duplicate values or nodes, but a sequence is never an item in another sequence. When a new sequence is created by concatenating two or more input sequences, the new sequence contains all the items of the input sequences and its length is the sum of the lengths of the input sequences.
In places where the grammar calls for ExprSingle (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ExprSingle), such as the arguments of a function call, any expression that contains a top-level comma operator must be enclosed in parentheses. Empty parentheses can be used to denote an empty sequence.
Here are some examples of expressions that construct sequences:
The result of this expression is a sequence of five integers:
(10, 1, 2, 3, 4)
This expression combines four sequences of length one, two, zero, and two, respectively, into a single sequence of length five. The result of this expression is the sequence 10, 1, 2, 3, 4.
(10, (1, 2), (), (3, 4))
The result of this expression is a sequence containing all salary children of the context node followed by all bonus children.
(salary, bonus)
Assuming that $price is bound to the value 10.50, the result of this expression is the sequence 10.50, 10.50.
($price, $price)
A range expression can be used to construct a sequence of consecutive integers. Each of the operands of the to operator is converted as though it was an argument of a function with the expected parameter type xs:integer. A type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) [err:XP0006 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0006)] is raised if either operand cannot be converted to a single integer. If the integer derived from the first operand is greater than the integer derived from the second operand, the result of the range expression is an empty sequence. Otherwise, the result is a sequence containing the two integer operands and every integer between the two operands, in increasing order.
This example uses a range expression as one operand in constructing a sequence. It evaluates to the sequence 10, 1, 2, 3, 4.
(10, 1 to 4)
This example constructs a sequence of length one containing the single integer 10.
10 to 10
The result of this example is a sequence of length zero.
15 to 10
This example uses the fn:reverse function to construct a sequence of six integers in decreasing order. It evaluates to the sequence 15, 14, 13, 12, 11, 10.
fn:reverse(10 to 15)
3.3.2 Filter Expressions
| [72] | FilterExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-FilterExpr) | ::= | PrimaryExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-PrimaryExpr) PredicateList (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-PredicateList) |
| [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 filter expression consists simply of a primary expression followed by zero or more predicates. The result of the filter expression consists of all the items returned by the primary expression for which all the predicates are true. If no predicates are specified, the result is simply the result of the primary expression. This result may contain nodes, atomic values, or any combination of these. The ordering of the items returned by a filter expression is the same as their order in the result of the primary expression. Context positions are assigned to items based on their ordinal position in the result sequence. The first context position is 1.
Here are some examples of filter expressions:
Given a sequence of products in a variable, return only those products whose price is greater than 100.
$products[price gt 100]
List all the integers from 1 to 100 that are divisible by 5. (See 3.3.1 Constructing Sequences for an explanation of the to operator.)
(1 to 100)[. mod 5 eq 0]
The result of the following expression is the integer 25:
(21 to 29)[5]
The following example illustrates the use of a filter expression as a step in a path expression. It returns the element node within the specified document whose ID value is "tiger":
fn:doc("zoo.xml")/fn:id('tiger')
3.3.3 Combining Node Sequences
| [47] | UnionExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-UnionExpr) | ::= | IntersectExceptExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-IntersectExceptExpr) ( ("union" | "|") IntersectExceptExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-IntersectExceptExpr) )* |
| [48] | IntersectExceptExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-IntersectExceptExpr) | ::= | InstanceofExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-InstanceofExpr) ( ("intersect" | "except") InstanceofExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-InstanceofExpr) )* |
XQuery provides the following operators for combining sequences of nodes:
The union and | operators are equivalent. They take two node sequences as operands and return a sequence containing all the nodes that occur in either of the operands.
The intersect operator takes two node sequences as operands and returns a sequence containing all the nodes that occur in both operands.
The except operator takes two node sequences as operands and returns a sequence containing all the nodes that occur in the first operand but not in the second operand.
All these operators eliminate duplicate nodes from their result sequences based on node identity. If ordering mode (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-ordering-mode) is ordered, the resulting 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.
If an operand of union, intersect, or except contains an item that is not a node, 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)]
Here are some examples of expressions that combine sequences. Assume the existence of three element nodes that we will refer to by symbolic names A, B, and C. Assume that the variables $seq1, $seq2 and $seq3 are bound to the following sequences of these nodes:
$seq1 is bound to (A, B)
$seq2 is bound to (A, B)
$seq3 is bound to (B, C)
Then:
$seq1 union $seq2 evaluates to the sequence (A, B).
$seq2 union $seq3 evaluates to the sequence (A, B, C).
$seq1 intersect $seq2 evaluates to the sequence (A, B).
$seq2 intersect $seq3 evaluates to the sequence containing B only.
$seq1 except $seq2 evaluates to the empty sequence.
$seq2 except $seq3 evaluates to the sequence containing A only.
In addition to the sequence operators described here, [XQuery 1.0 and XPath 2.0 Functions and Operators (http://www.w3.org/TR/2004/WD-xquery-20040723/#FunctionsAndOperators)] includes functions for indexed access to items or sub-sequences of a sequence, for indexed insertion or removal of items in a sequence, and for removing duplicate items from a sequence.
3.4 Arithmetic Expressions
XQuery provides arithmetic operators for addition, subtraction, multiplication, division, and modulus, in their usual binary and unary forms.
| [45] | AdditiveExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-AdditiveExpr) | ::= | MultiplicativeExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-MultiplicativeExpr) ( ("+" | "-") MultiplicativeExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-MultiplicativeExpr) )* |
| [46] | MultiplicativeExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-MultiplicativeExpr) | ::= | UnionExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-UnionExpr) ( ("*" | "div" | "idiv" | "mod") UnionExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-UnionExpr) )* |
| [53] | UnaryExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-UnaryExpr) | ::= | ("-" | "+")* ValueExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ValueExpr) |
| [54] | ValueExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-ValueExpr) | ::= | ValidateExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ValidateExpr) | PathExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-PathExpr) |
A subtraction operator must be preceded by whitespace if it could otherwise be interpreted as part of the previous token. For example, a-b will be interpreted as a name, but a - b and a -b will be interpreted as arithmetic operations.
An arithmetic expression is evaluated by applying the following rules, in order, until an error is raised or a value is computed:
Atomization (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-atomization) is applied to each operand.
If either operand is now an empty sequence, the result of the operation is an empty sequence.
If either operand is now a sequence of length greater than one, a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) is raised.[err:XP0006 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0006)]
If either operand is now of type xdt:untypedAtomic, it is cast to xs:double. If the cast fails, a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) is raised.[err:XP0021 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0021)]
If the operand types are now valid for the given operator, the operator is applied to the operands, resulting in an atomic value or a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) (for example, an error might result from dividing by zero.) The combinations of atomic types that are accepted by the various arithmetic operators, and their respective result types, are listed in B.2 Operator Mapping together with the functions in [XQuery 1.0 and XPath 2.0 Functions and Operators (http://www.w3.org/TR/2004/WD-xquery-20040723/#FunctionsAndOperators)] that define the semantics of the operation for each type.
If the operand types are still not valid for the given operator, a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) is raised.
XQuery supports two division operators named div and idiv. Each of these operators accepts two operands of any numeric type. As described in [XQuery 1.0 and XPath 2.0 Functions and Operators (http://www.w3.org/TR/2004/WD-xquery-20040723/#FunctionsAndOperators)], $arg1 idiv $arg2 is equivalent to ($arg1 div $arg2) cast as xs:integer except for error cases.
Here are some examples of arithmetic expressions:
The first expression below returns the xs:decimal value -1.5, and the second expression returns the xs:integer value -1:
-3 div 2
-3 idiv 2
Subtraction of two date values results in a value of type xdt:dayTimeDuration:
$emp/hiredate - $emp/birthdate
This example illustrates the difference between a subtraction operator and a hyphen:
$unit-price - $unit-discount
Unary operators have higher precedence than binary operators, subject of course to the use of parentheses. Therefore, the following two examples have different meanings:
-$bellcost + $whistlecost
-($bellcost + $whistlecost)
Note:
Multiple consecutive unary arithmetic operators are permitted by XQuery for compatability with [XPath 1.0 (http://www.w3.org/TR/2004/WD-xquery-20040723/#XPath)].
3.5 Comparison Expressions
Comparison expressions allow two values to be compared. XQuery provides three kinds of comparison expressions, called value comparisons, general comparisons, and node comparisons.
| [43] | ComparisonExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-ComparisonExpr) | ::= |
RangeExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-RangeExpr) ( (ValueComp (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ValueComp) |
| [56] | ValueComp (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-ValueComp) | ::= | "eq" | "ne" | "lt" | "le" | "gt" | "ge" |
| [55] | GeneralComp (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-GeneralComp) | ::= | "=" | "!=" | "<" | "<=" | ">" | ">=" |
| [57] | NodeComp (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-NodeComp) | ::= | "is" | "<<" | ">>" |
3.5.1 Value Comparisons
The value comparison operators are eq, ne, lt, le, gt, and ge. Value comparisons are used for comparing single values. The result of a value comparison is defined by applying the following rules, in order:
Atomization (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-atomization) is applied to each operand. If the result, called an atomized operand, contains more than one atomic value, 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 either atomized operand is an empty sequence, the result of the value comparison is an empty sequence.
Any atomized operand that has the dynamic type xdt:untypedAtomic is cast to the type xs:string.
Note:
The purpose of this rule is to make value comparisons transitive. It is recognized that the general comparison operators have a different rule for casting of xdt:untypedAtomic operands. It is also recognized that transitivity of value comparisons may be compromised by loss of precision during type conversion (for example, two int values that differ slightly may both be considered equal to the same float value because float has less precision than int).
If both atomized operands consist of exactly one atomic value, then the result of the comparison is true if the value of the first operand is (equal, not equal, less than, less than or equal, greater than, greater than or equal) to the value of the second operand; otherwise the result of the comparison is false. B.2 Operator Mapping defines which combinations of atomic types are comparable, and how the comparison operators are mapped into supporting functions. If the value of the first atomized operand is not comparable with the value of the second atomized operand, a type error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-type-error) is raised.[err:XP0004 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0004)][err:XP0006 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0006)]
Here are some examples of value comparisons:
The following comparison is true only if $book1 has exactly one author subelement and its typed value is "Kennedy" as an instance of xs:string or xdt:untypedAtomic. If $book1 has more than one author subelement, 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 $book1 has no author subelement, the result of the expression is the empty sequence.
$book1/author eq "Kennedy"
The following path expression contains a predicate that selects products whose weight is greater than 100. For any product that does not have a weight subelement, the value of the predicate is the empty sequence, and the product is not selected:
//product[weight gt 100]
The following comparisons are true because, in each case, the two constructed nodes have the same value after atomization, even though they have different identities and/or names:
<a>5</a> eq <a>5</a>
<a>5</a> eq <b>5</b>
The following comparison is true if my:hatsize and my:shoesize are both user-defined types that are derived by restriction from a primitive numeric type:
my:hatsize(5) eq my:shoesize(5)
3.5.2 General Comparisons
The general comparison operators are =, !=, <, <=, >, and >=. General comparisons are existentially quantified comparisons that may be applied to operand sequences of any length. The result of a general comparison that does not raise an error is always true or false.
Atomization (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-atomization) is applied to each operand of a general comparison. The result of the comparison is true if and only if there is a pair of atomic values, one belonging to the result of atomization of the first operand and the other belonging to the result of atomization of the second operand, that have the required magnitude relationship. Otherwise the result of the general comparison is false. The magnitude relationship between two atomic values is determined as follows:
If either atomic value has the dynamic type xdt:untypedAtomic, that value is cast to a required type, which is determined as follows:
If the dynamic type of the other atomic value is a numeric type, the required type is xs:double.
If the dynamic type of the other atomic value is xdt:untypedAtomic, the required type is xs:string.
Otherwise, the required type is the dynamic type of the other atomic value.
If the cast to the required type fails, a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) is raised.[err:XP0021 (http://www.w3.org/TR/2004/WD-xquery-20040723/#ERRXP0021)]
Note:
The purpose of this rule is to preserve backward compatability with XPath 1.0, in which (for example) x < 17 is a numeric comparison if x is an untyped value. It is recognized that the value comparison operators have a different rule for casting of xdt:untypedAtomic operands.
After any necessary casting, the atomic values are compared using one of the value comparison operators eq, ne, lt, le, gt, or ge, depending on whether the general comparison operator was =, !=, <, <=, >, or >=. The values have the required magnitude relationship if the result of this value comparison is true.
When evaluating a general comparison in which either operand is a sequence of items, an implementation may return true as soon as it finds an item in the first operand and an item in the second operand that have the required magnitude relationship. Similarly, a general comparison may raise a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error) as soon as it encounters an error in evaluating either operand, or in comparing a pair of items from the two operands. As a result of these rules, the result of a general comparison is not deterministic in the presence of errors.
Here are some examples of general comparisons:
The following comparison is true if the typed value of any author subelement of $book1 is "Kennedy" as an instance of xs:string or xdt:untypedAtomic:
$book1/author = "Kennedy"
The following example contains three general comparisons. The value of the first two comparisons is true, and the value of the third comparison is false. This example illustrates the fact that general comparisons are not transitive.
(1, 2) = (2, 3)
(2, 3) = (3, 4)
(1, 2) = (3, 4)
The following example contains two general comparisons, both of which are true. This example illustrates the fact that the = and != operators are not inverses of each other.
(1, 2) = (2, 3)
(1, 2) != (2, 3)
Suppose that $a, $b, and $c are bound to element nodes with type annotation xdt:untypedAtomic, with string values "1", "2", and "2.0" respectively. Then ($a, $b) = ($c, 3.0) returns false, because $b and $c are compared as strings. However, ($a, $b) = ($c, 2.0) returns true, because $b and 2.0 are compared as numbers.
3.5.3 Node Comparisons
Node comparisons are used to compare two nodes, by their identity or by their document order (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-document-order). The result of a node comparison is defined by applying the following rules, in order:
Each operand must be either a single node or an empty sequence; otherwise 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 either operand is an empty sequence, the result of the comparison is an empty sequence.
A comparison with the is operator is true if the two operands have the same identity, and are thus the same node; otherwise it is false. See [XQuery 1.0 and XPath 2.0 Data Model (http://www.w3.org/TR/2004/WD-xquery-20040723/#datamodel)] for a definition of node identity.
A comparison with the << operator returns true if the first operand node precedes the second operand node in document order (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-document-order); otherwise it returns false.
A comparison with the >> operator returns true if the first operand node follows the second operand node in document order (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-document-order); otherwise it returns false.
Here are some examples of node comparisons:
The following comparison is true only if the left and right sides each evaluate to exactly the same single node:
//book[isbn="1558604820"] is //book[call="QA76.9 C3845"]
The following comparison is false because each constructed node has its own identity:
<a>5</a> is <a>5</a>
The following comparison is true only if the node identified by the left side occurs before the node identified by the right side in document order:
//purchase[parcel="28-451"] << //sale[parcel="33-870"]
3.6 Logical Expressions
A logical expression is either an and-expression or an or-expression. If a logical expression does not raise an error, its value is always one of the boolean values true or false.
| [41] | OrExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-OrExpr) | ::= | AndExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AndExpr) ( "or" AndExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-AndExpr) )* |
| [42] | AndExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#prod-xquery-AndExpr) | ::= | ComparisonExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ComparisonExpr) ( "and" ComparisonExpr (http://www.w3.org/TR/2004/WD-xquery-20040723/#doc-xquery-ComparisonExpr) )* |
The first step in evaluating a logical expression is to find the effective boolean value (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-ebv) of each of its operands (see 2.3.3 Effective Boolean Value).
The value of an and-expression is determined by the effective boolean values (EBV's) of its operands. If an error is raised during computation of one of the effective boolean values, an and-expression may raise a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error), as shown in the following table:
| AND: | EBV2 = true | EBV2 = false | error in EBV2 |
| EBV1 = true | true | false | error |
| EBV1 = false | false | false | false or error |
| error in EBV1 | error | false or error | error |
The value of an or-expression is determined by the effective boolean values (EBV's) of its operands. If an error is raised during computation of one of the effective boolean values, an or-expression may raise a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error), as shown in the following table:
| OR: | EBV2 = true | EBV2 = false | error in EBV2 |
| EBV1 = true | true | true | true or error |
| EBV1 = false | true | false | error |
| error in EBV1 | true or error | error | error |
The order in which the operands of a logical expression are evaluated is implementation-dependent (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-implementation-dependent). The tables above are defined in such a way that an or-expression can return true if the first expression evaluated is true, and it can raise an error if evaluation of the first expression raises an error. Similarly, an and-expression can return false if the first expression evaluated is false, and it can raise an error if evaluation of the first expression raises an error. As a result of these rules, a logical expression is not deterministic in the presence of errors, as described in 2.5.3 Errors and Optimization. This is illustrated in the examples below.
Here are some examples of logical expressions:
The following expressions return true:
1 eq 1 and 2 eq 2
1 eq 1 or 2 eq 3
The following expression may return either false or raise a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error):
1 eq 2 and 3 idiv 0 = 1
The following expression may return either true or raise a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error):
1 eq 1 or 3 idiv 0 = 1
The following expression must raise a dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error):
1 eq 1 and 3 idiv 0 = 1
In addition to and- and or-expressions, XQuery provides a function named fn:not that takes a general sequence as parameter and returns a boolean value. The fn:not function is defined in [XQuery 1.0 and XPath 2.0 Functions and Operators (http://www.w3.org/TR/2004/WD-xquery-20040723/#FunctionsAndOperators)]. The fn:not function reduces its parameter to an effective boolean value (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-ebv). It then returns true if the effective boolean value of its parameter is false, and false if the effective boolean value of its parameter is true. If an error is encountered in finding the effective boolean value of its operand, fn:not raises the same dynamic error (http://www.w3.org/TR/2004/WD-xquery-20040723/#dt-dynamic-error).


