Skip to Content
XQuery, 2nd Edition
book

XQuery, 2nd Edition

by Priscilla Walmsley
December 2015
Intermediate to advanced
762 pages
19h 13m
English
O'Reilly Media, Inc.
Content preview from XQuery, 2nd Edition

Chapter 12. Prologs, Modules, and Variables

This chapter covers the structure of queries in more detail. It discusses the query prolog and its various declarations. It then describes how to assemble queries from multiple modules, declare global variables, and define external functions.

Structure of a Query: Prolog and Body

An XQuery query is made up of two parts: a prolog and a body. The query prolog is an optional section that appears at the beginning of a query. The prolog can contain various declarations that affect settings used in evaluating the query. This includes namespace declarations, imports of schemas, variable declarations, function declarations, and other setting values. In a query module of any size, the prolog is actually likely to be much larger than the body.

Example 12-1 shows a query with a prolog containing several different types of declarations.

Example 12-1. A query prolog
xquery version "3.0";
declare default element namespace "http://datypic.com/cat";
declare boundary-space preserve;
declare namespace ord = "http://datypic.com/ord";
import schema namespace prod="http://datypic.com/prod"
                        at "prod.xsd";
declare function local:getProdNums
  ($catalog as element()) as xs:integer*
  {for $prod in $catalog/product
   return xs:integer($prod/number)};

The query body is a single expression, but that expression can consist of a sequence of one or more expressions that are separated by commas. Example 12-2 shows a query body that contains a sequence of two expressions, a constructed ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

XQuery

XQuery

Priscilla Walmsley
XSLT

XSLT

Doug Tidwell
Learning XSLT

Learning XSLT

Michael Fitzgerald

Publisher Resources

ISBN: 9781491915080Purchase bookErrata Page