Built-in Functions

XQuery has a set of built-in functions and operators, including many that are familiar from other languages, and some that are used for customized XML processing. The complete list of built-in functions is found in [XQ-FO]. This section focuses on the most commonly used functions, some of which must be understood to follow what is said in the rest of the chapter.

SQL programmers will be familiar with the min(), max(), count(), sum(), and avg() functions. The following query returns the titles of books that are more expensive than the average book:

let $b := doc("books.xml")//book
let $avg := average( $b//price )
return $b[price > $avg]

For our sample data, Listing 1.18 shows the result of this query.

Listing 1.18. Result ...

Get XQuery from the Experts: A Guide to the W3C XML Query Language now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.