Examples

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.

XQueryServlet (just eXist, no Cocoon)

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.
Guess a Number Simple number guessing game to illustrate different servlet features.
Built-in functions Extracts the function documentation for all available functions. It uses the transform function to transform XML output into HTML using an XSL stylesheet (also check the function search interface.
Session example Presents a login page. Only valid database users can log in. User and password are stored in the HTTP session.
Basic form example Presents a form page. The response echoes the name entered.
Form example with XUpdate Presents a form page. The response echoes all the names entered since database creation.
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.
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.
Transform XML fragments to JSON An XQuery does not necessarily need to return XML.
Redirecting HTTP requests eXist's RedirectorServlet calls a user-defined XQuery to decide how a HTTP request is handled. The XML fragment returned by the query determines where the request is directed to. This happens transparently to the client.

XQueryGenerator (using Cocoon)

Simple HTML Example Prints a table in HTML with 10x10 cells.
Fibonacci Calculates the first 10 Fibonacci numbers.
Built-in functions Display and search all functions currently registered with the database.
XML Acronyms XQuery version of the XML Acronym Demystifier, entirely implemented in XQuery.
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.
Bibliography 2 Another bibliographic demo from previous releases of eXist. No AJAX.

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!

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.
eXist's XSP Logicsheet
XML Acronyms An XSP-based version of the XML Acronym Demystifier