Qexo - The GNU Kawa implementation of XQuery

Qexo is a partial implementation of the XML Query language. It achieves high performance because a query is compiled down to Java bytecodes using the Kawa framework. Kawa also includes a proof-of-concept implementation of XSLT.

The Qexo mailing list is has address qexo-general@gnu.org. To subscribe, unsubscribe, or view the archives use the information page.

Qexo 1.9.1 is now available. Here are instructions for getting it.



You can read a short introduction to XQuery;
an article on the XQuery Data Model and Types;
and a longer article on generating XML and HTML using XQuery.

You can read here for more on running Qexo.
Here is an article debugging and finding errors in Qexo programs.

If you're interested in servlets and web applications, you can read an article showing how to write and install a trivial web application, or an article with an older but useful information.


Data conversion

Here is a program for converting a table:

let $newline := "
$result := (document("tab.xml")/result)
{for $x in ($result/row)
      return (<tr>{
        for $y in ($x/fld1) return (<td><b>{children($y)}</b></td>),
        for $y in ($x/fld2) return (<td>{list(100,children($y))}</td>)}</tr>,

This will convert an input table like this:

yielding an output table like this:
<tr><td><b>a1</b></td><td><list>100 12</list></td></tr>
<tr><td><b>b1</b></td><td><list>100 22</list></td></tr>

Formatted table generation

The following program generates a 10x10 multiplication table:

  for $y in 1 to 10 return (
      for $x in 1 to 10 return
        let $bg:=(if($x mod 2 + $y mod 2 <= 0) then "lightgreen"
                  else if ($y mod 2 <= 0) then "yellow"
                  else if ($x mod 2 <= 0) then "lightblue"
                  else "white"),
          return <td align="right" bgcolor="{$bg}">{
            if ($x > 1 and $y > 1) then $prod else <b>{$prod}</b>}</td>

This is the result:

Defining a function

Here is an example of defining and using a recursive function:

define function descendent-or-self ($x) {
  $x, for $z in children($x) return descendent-or-self($z) }
descendent-or-self (<a>text1<b>text2</b></a>)
The result is: <a>text1<b>text2</b></a>text1<b>text2</b>text2

Photo album

I re-wrote from XML to XQuery my scripts for organizing my digital photos. The new shell script which calls pictures.xql is more readable, has similar size, yet provide more functionality. Here is an an example of the output (optimized for Mozilla).

How to get and install Qexo

Qexo is part of Kawa. The easiest way to try Qexo out it to download a runnable jar. Alternatively, you can get the source code. Both are available from the Kawa ftp site http://ftp.gnu.org/pub/gnu/kawa/ or a mirror. Follow these instructions to build from source code. To keep up with the very latest changes you might prefer to get Kawa from the SVN repository, as described in the Kawa manual.


You run Kawa-XQuery just the way you run Kawa, except you need to specify the --xquery flag to specify the language. (By default Kawa expects Scheme source code.)

For example you can type in xquery expression directly at the command line. If the end of a the line occurs where the seen input is a valid XQuery expression, then that expression will be treated as a complete expression. (However, when parsing a file the entire file is parsed.)

$ java -jar kawa-1.9.jar --xquery
(: 1 :) for $x in (3,4,5) return <a>{$x}</a>
(: 2 :) string(<a>3+5 is {3+5}</a>)
3+5 is 8
(: 3 :)

You can also compile an XQuery program to a Java application:

$ java -jar kawa-1.9.jar --xquery --main -C prog.xql
$ java -cp .:kawa-1.9.jar prog

You can read here for more on running Qexo.

Generating and Running Servlets

You can compile an XQuery program to a Servlet. Here is a simple web application example. This article has additional but older information. The servlet can be run in a servlet-aware web server, or as a CGI script.


Qexo is is part of Kawa, whose licence is the X11/MIT license.

Per Bothner