O'Reilly logo

XQuery from the Experts: A Guide to the W3C XML Query Language by Philip Wadler, Jim Tivy, Jérôme Siméon, Michael Rys, Jonathan Robie, Michael Kay, Mary Fernández, Denise Draper, Don Chamberlin, Howard Katz - Editor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required