Chapter 3. Expressions: XQuery Building Blocks

The basic unit of evaluation in the XQuery language is the expression. A query contains expressions that can be made up of a number of sub-expressions, which may themselves be composed from other sub-expressions. This chapter explains the XQuery syntax, and covers the most basic types of expressions that can be used in queries: literals, variables, function calls, and comments.

Categories of Expressions

A query can range in complexity from a single expression such as 2+3, to a complex composite expression like a FLWOR. Within a FLWOR, there may be other expressions, such as $prodDept = "ACC", which is a comparison expression, and doc("catalog.xml")/catalog/product, which is a path expression. Within these expressions, there are further expressions, such as "ACC", which is a literal, and $prodDept, which is a variable reference.

The categories of expressions available are summarized in Table 3-1, along with the number of the chapter that covers them. Every expression evaluates to a sequence, which may be a single atomic value, a single node, the empty sequence, or multiple atomic values and/or nodes.

Table 3-1. Categories of expressions

Category

Description

Operators or keywords

Chapter

Primary

The basics: literals, variables, function calls, and parenthesized expressions

 

3

Comparison

Comparison based on value, node identity, or document order

=, !=, <, <=, >, >=, eq, ne, lt, le, gt, ge, is, <<, >>

3

Conditional

If-then-else expressions

if, then, else

3

Logical

Boolean and/or operators

or, and

3

Path

Selecting nodes from XML documents

/, //, .., ., child::, etc.

4

Constructor

Adding XML to the results

<, >, element, attribute

5

FLWOR

Controlling the selection and processing of nodes

for, let, where, order by, return

6

Quantified

Determining whether sequences fulfill specific conditions

some, every, in, satisfies

6

Sequence-related

Creating and combining sequences

to, union (|), intersect, except

9

Type-related

Casting and validating values based on type

instance of, typeswitch, cast as, castable, treat, validate

11, 14

Arithmetic

Adding, subtracting, multiplying, and dividing

+, -, *, div, idiv, mod

16

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.46.92