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.
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.
Here is a program for converting a table:
let $newline := " ", $result := (document("tab.xml")/result) return (<table> {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>, $newline) }</table>,$newline)
This will convert an input table like this:
<result> <row> <fld1>a1</fld1> <fld2>12</fld2> </row> <row> <fld1>b1</fld1> <fld2>22</fld2> </row> </result>yielding an output table like this:
<table> <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> </table>
The following program generates a 10x10 multiplication table:
<table>{ for $y in 1 to 10 return ( <tr>{ 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"), $prod:=$x*$y return <td align="right" bgcolor="{$bg}">{ if ($x > 1 and $y > 1) then $prod else <b>{$prod}</b>}</td> }</tr>, " ") }</table>," "
This is the result:
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 |
3 | 6 | 9 | 12 | 15 | 18 | 21 | 24 | 27 | 30 |
4 | 8 | 12 | 16 | 20 | 24 | 28 | 32 | 36 | 40 |
5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 |
6 | 12 | 18 | 24 | 30 | 36 | 42 | 48 | 54 | 60 |
7 | 14 | 21 | 28 | 35 | 42 | 49 | 56 | 63 | 70 |
8 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 | 80 |
9 | 18 | 27 | 36 | 45 | 54 | 63 | 72 | 81 | 90 |
10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 100 |
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
You can try out Qexo without downloading it by using the XQuery sandbox hosted at cocoonhive.org. (Thanks to Ivelin Ivanov for setting this up.)
Qexo is part of Kawa. The easiest way to try it 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 However, XQuery is new and constantly changing, so you might prefer to get Kawa from the CVS 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.8.jar --xquery xquery[1]: for $x in (3,4,5) return <a>{$x}</a> <a>3</a><a>4</a><a>5</a> xquery[2]: string-value(<a>3+5 is {3+5}</a>) 3+5 is 8 xquery[3]:
You can also compile an XQuery program to a Java application:
$ java -jar kawa-1.8.jar --xquery --main -C prog.xql $ java -cp .:kawa-1.8.jar prog
You can read here for more on running Qexo.
You can compile an XQuery program to a Servlet. Here is a simple web application example. This article has addition but older information. The servlet can be run in a servlet-aware web server, or as a CGI script.
Kawa-XQuery is available under the Kawa licence, which is the GNU General Public License with some extra options.