nowadays it is possible to use it in web
development.
XQuery is more easy and intuitive than XSLT.
Transforms described with XQuery expressions are
easier to understand, maintenance and modify than
transform expressions written in XSLT.
2.4 Functions
When an XQuery expression becomes large and
complex, it is often much easier to understand if it is
divided into functions. These functions can be
reused in other parts of the expression. Functions
can be recursive, which is a good help for processing
the recursive structure of XML (Brundage, 2004).
It is possible to organize functions in library
modules. These modules can be used and 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.
Functions defined in library modules are
namespace-qualified. This means that functions with
same name can exist into different namespaces. Any
module can import another module using a module
import, which specifies the URI of the module to be
imported. It may also specify the location where the
module can be found.
2.5 External functions
XQuery allows calls to external functions
implemented in the same language than the
environment under XQuery engine is in execution,
such as Java or C#. The environment can provide
external functions and variables to XQuery. To
access to external elements, a query must declare
them in its prologue. The mechanism by which this
is done varies from one implementation to the next.
XQuery itself provides only the syntax to use when
declaring these externals, shown in table 4.
Table 4: External function definition.
define function out($v as xs:integer)
as xs:integer external
External functions are equal to ordinary user-
defined functions except that the external keyword is
used instead of a function body. XQuery does not
specify how such functions and variables are made
available by the external environment, or how
function parameters and arguments are converted
between the external environment and XQuery, so it
depends of the vendor implementation.
3 APPLYING XQUERY IN WEB
DEVELOPMENT
XML is one of the most important technologies in
web development. One of the main objectives in
design of XQuery is to allow that XQuery can be
applied like a XML manipulation and transformation
language. Thus XQuery offers tools to work with
XML. Moreover, XQuery can be successfully
applied in environments where XML works. Some
of the most important applications in web
environments are showed in table 5.
Table 5: XQuery in web development
- Management XML native databases in the same
way than SQL manages relational databases.
- Generate web interfaces in the same way than
XSLT.
- Call web-services.
- Syndication with RSS.
In section 2, main characteristic of XQuery to
web development have been defined. This section
shows how to apply those characteristics to
implement each layer showed in figure 1.
3.1 User interface
This work has described, in sections before, how it is
possible to build web user interfaces using XQuery
in a similar way than XSLT. This generation
interface technique has been improvement with the
inclusion of XHTML and CSS in web browsers.
The main differences between XSLT and XQuery
are of two kinds. First, they have different
requirements, and therefore a design decision that
was appropriate for XSLT would not necessarily be
right for XQuery, and vice versa. The second kind of
difference results from their being designed by
different people from different communities and
computing traditions, with different beliefs about
what constitutes good design, and different
experiences as to what works well and what doesn't.
There is one important difference between XQuery
and most template systems: With XQuery, it is also
possible to define functions that return HTML
fragments, and to pass those fragments though to
other functions. With most template systems, it is
BUILDING WEB APPLICATIONS WITH XQUERY - Integrating technologies in web development
367