1. XForms Support in eXist

eXist now has broad support for the W3C XForms standard. It offers a client-side (XSLTForms) and a server-side (betterFORM) implementation and thus is ideally equipped to build complete applications that use XML from front to back.

However, eXist will also work with other XForms processors, like Orbeon or Chiba (the ancestor of betterFORM).

As eXist has support for RESTful interactions saving XML data is as easy as using a HTTP PUT submission. For more complex tasks, you can submit your XForms instances to an XQuery, post-process them and get the results back into your form. Several examples are provided.

2. Using betterFORM inside of eXist

betterFORM is a server-side W3C XForms 1.1 implementation written in Java that now is closely integrated within eXist. It covers 99% of the XForms recommendation and has been extensively tested against the official XForms 1.1 Test Suite. All modern browsers are supported without the need for plugins. betterFORM can also be obtained (via Github) and run separately as a standard webapp. It is published under the BSD license.

With betterFORM XHTML/XForms document are transcoded on the server into plain (X)HTML + JavaScript. The resulting page uses an AJAX layer to keep client and server in sync and provide an attractive user interface without the need of writing a single line of script code.

XForms processing with betterFORM is handled by a servlet filter (XFormsFilter) which nicely integrates with the URL Rewriting feature of eXist. You can use XQuery to generate your XForms markup and process it in a single request.

2.1. Getting started

betterFORM by now is activated once you have installed eXist on your machine. By default betterFORM is configured to run XForms exclusively from the database.

To execute a XHTML/XForms document it is sufficient to store it into your database (using WebDAV or the admin client) and access it via the REST interface.

betterFORM can also be configured to listen only for a certain collections or to fetch documents from the filesystem (somewhere below ‘webapp’ dir) by changing the filter mapping in webapp/WEB-INF/web.xml.

Example: Configure filtermapping in web.xml

                        <filter-mapping>
                            <filter-name>XFormsFilter</filter-name>
                            <url-pattern>/rest/db/*</url-pattern>
                        </filter-mapping>
                        <filter-mapping>
                            <filter-name>XFormsFilter</filter-name>
                            <servlet-name>XFormsPostServlet</servlet-name>
                        </filter-mapping>
                        <filter-mapping>
                            <filter-name>XQueryURLRewrite</filter-name>
                            <url-pattern>/*</url-pattern>
                        </filter-mapping>                                                
                    

2.2. betterFORM Add-ons

To ease the work with betterFORM it is highly recommended to install the betterFROM dashboard along with the FeatureExplorer and the demo application. Before the betterFORM add-ons can be used the examples (eXist-db-shipped files) must be installed via the Admin panel

See the XForms example page for more betterFORM demo & reference forms.

3. Using XSLTForms inside of eXist

eXist now directly supports XForms via Alain Couthures' excellent XSLTForms processor. XSLTForms implements the XForms standard within the browser and is thus easy to integrate. XSLTForms transforms the XForms xml into an XHTML page with javascript that can process XForms.

3.1. Using XSLTForms inside of eXist

XSLTForms mainly consists of two components:

The XSLT stylesheet can either be applied server-side or within the client, i.e. the browser. To let the browser do the job, all you have to do is to prepend an XSL PI to your XForms document, pointing to the xsltforms/xsltforms.xsl stylesheet:

Example: Activate xforms by using XSL PI

<?xml-stylesheet href="xsltforms/xsltforms.xsl" type="text/xsl"?>
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms">
        ...
    </html>
    

Please have a look at hello.xml for a very basic example using client-side transformation.

When applying the stylesheet server-side, you need to make sure serialization parameters are correctly set. For example, you can apply the stylesheet within an XQueryURLRewrite controller pipeline:

Example: Applying the stylesheet server-side via controller.xql

<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
        <view>
            <forward servlet="XSLTServlet">
                (: Apply xsltforms.xsl stylesheet :)
        		<set-attribute name="xslt.stylesheet"
        			value="xsltforms/xsltforms.xsl"/>
        	    <set-attribute name="xslt.output.omit-xml-declaration" value="yes"/>
        	    <set-attribute name="xslt.output.indent" value="no"/>
        	    <set-attribute name="xslt.output.media-type" value="text/html"/>
        	    <set-attribute name="xslt.output.method" value="xhtml"/>
        	    <set-attribute name="xslt.baseuri" value="xsltforms/"/>
        	</forward>
        </view>
        <cache-control cache="yes"/>
    </dispatch>

It is important to set the indent serialization parameter to "no", otherwise you'll get javascript errors when viewing the page. Also, if you apply the stylesheet server-side, make sure you removed the processing instruction from the source file or the browser will try to run the stylesheet as well (which most likely leads to errors).

The "task manager" and Shakespeare examples are both using a server-side transformation. Please have a look at the corresponding controller.xql in webapp/xforms/controller.xql to see how it is done.

3.2. Known Issues

Loading an XForms document through eXist's REST interface: when the REST server finds an xsl-stylesheet processing instruction in a document, it tries to apply the referenced stylesheet server-side. Unfortunately, the default serialization settings of the REST interface set indent="yes", which leads to problems with the XForms javascript library.

As a workaround, you can append a request parameter ?_indent=no to the REST URI. However, the recommended approach would be to use XQueryURLRewrite to properly handle those requests and apply the stylesheet.

4. Additional XForms Resources

4.1. XForms examples running in eXist

4.2. Mailing Lists

4.3. XForms Specifications

4.4. Useful

Wolfgang M. Meier