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

Library Modules

Functions can be put in library modules, which can be imported by any query. Every module in XQuery is either a main module, which contains a query body to be evaluated, or a library module, which has a module declaration but no query body. A library module begins with a module declaration, which provides a URI that identifies the module for imports, as shown in Listing 1.20.

Listing 1.20. Module Declaration for a Library Module
module "http://example.com/xquery/library/book"

define function toc($book-or-section as element())
  as element()*
{
  for $section in $book-or-section/section
  return
    <section>
      { $section/@* , $section/title , toc($section) }
    </section>
}

Functions and variable definitions in library modules are namespace-qualified. ...

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