This chapter describes the facilities in XQuery for selecting, filtering, and joining data from one or more input documents. It covers the syntax of FLWORs (for
, let
, where
, order by
, return
) and quantitative expressions.
Chapter 4 described how to use path expressions to select elements from input documents. For example, the expression:
doc("catalog.xml")//product[@dept = "ACC"]/name
can be used to select the names of all the products in the ACC department. You can add multiple predicates (expressions in square brackets) to filter the results based on more than one criterion. You can even add logical and other expressions to predicates, as in:
doc("catalog.xml")//product[@dept = "ACC" or @dept = "WMN"]/name
A path expression can be the entire content of a query; there is no requirement that there be a FLWOR expression in every query. Path expressions are useful for queries where no new elements and attributes are being constructed and the results don't need to be sorted. A path expression can be preferable to a FLWOR because it is more compact and some implementations will be able to evaluate it faster.
3.145.84.112