The examples below require some XML documents to be stored in the database. If you have not yet imported these files, go to Examples Setup.

Basic XQuery Examples

Simple Shakespeare Search Search Shakespeare's plays using XForms and the KWIC display module.
Guess a Number Simple number guessing game to illustrate different servlet features.
Simple HTML Example Prints a table in HTML with 10x10 cells.
Fibonacci Calculates the first 10 Fibonacci numbers.
Session example Presents a login page. Only valid database users can log in. User and password are stored in the HTTP session.
Twitter client A simple twitter client, which demonstrates how to use the http client library to retrieve XML data from external data sources. There's also an XProc version of this code.

More Complex Examples

XQuery Sandbox A web interface to execute XQueries on the server. Uses AJAX technology to validate your XQuery while you type. Requires Javascript to be enabled. Demonstrates more advanced techniques for writing web applications with XQuery, XML/HTML, CSS and Javascript.
XML Acronyms XQuery version of the XML Acronym Demystifier, entirely implemented in XQuery.
Search the Documentation A not too complex example featuring full text queries and post-processing of query results to show keywords in context.
XQuery Function Library Search The search interface for XQuery functions demonstrates usage of the NGram index and AJAX. The function documentation is generated once from the Java classes and stored in XQDoc format.
RESTful browser for Function Modules Browse the function documentation without AJAX. Directly access a function using a meaningful URL like "functions/module/function-name". A great example, which demonstrates how to use URL rewriting to construct RESTful URIs.
W3C XQuery Test suite (XQTS) Using this web application you can run the official XQuery test suite on eXist. You will need to download the test suite data (read the notice shown when you first access the page). The test runner is entirely written in XQuery and is a good example for a complex script using lots of AJAX.
First-class functions example Demonstrates the use of first-class functions. First-class functions are supported through the eXist-specific extension functions: util:function and util:call.
JSON Serialization Demo An jQuery dynatree example, the tree data is loaded via an AJAX call to an XQuery. This example shows that an XQuery can return non-xml output (JSON) with a serialization option.

Building Blocks for Web Applications

XForms Examples based on XML Forms.
XProc XProc: the XML pipeline language.
URL Rewriting eXist's XQueryURLRewrite servlet filter calls a user-defined XQuery to decide how a HTTP request is handled. The XML fragment returned by the query determines how the request is processed. This happens transparently to the client. One or more "views" can be applied to a request to further processes it. This is how most of the pages here are rendered (except the Cocoon examples). The RESTful functions browser implementation is a good demonstration of how to use URL rewriting and views. Please have a look at the source in EXIST_HOME/webapp/functions/.

Misc Examples

XInclude Sample Document Dynamically generates a page out of the database by expanding XInclude tags found in the source document.
Retrieve a document through REST Retrieves a document through the REST-style API. The document contains an XSL processing instruction. The XSL stylesheet is read from the database and applied to the output. Please note that also the CSS file referenced by the HTML output is loaded from the database.

Cocoon Examples

These are older examples based on different Cocoon features. Some of the examples have been rewritten in XQuery, so there are now two versions of these. Please note: the demonstrated features, in particular: XSP and the XML:DB transformer, are still functional, but not actively maintained!

Bibliography A bibliographic demo, based on the MODS bibliographic format, which is maintained by the Library of Congress. Shows session handling and user authentication as well as some AJAX goodies.
Cocoon XML:DB Pseudo-Protocol
Cocoon-based Database Browser A database browser which uses Cocoon's xmldb:// pseudo-protocol and XSL stylesheets for the rendering.

External Examples

AtomicWiki AtomicWiki is a combined Wiki and Weblog entirely written in XQuery (and some XSLT) and using XQuery as a scripting language within Wiki entries and Blog posts.