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. However, eXist will also work with other XForms processors like Orbeon or Chiba.
XSLTForms transforms the XForms xml into an XHTML page with javascript that can process XForms. As eXist has support for RESTful interactions the action of saving the XML representation of data provided by XForms can be as easy as using HTTP PUT method with an action attribute referencing an xml document in the XML Database. For more complex tasks, you can submit your XForms instances to an XQuery, post-process it there and get the results back into your XForms. Several examples are provided.
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:
<?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:
<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.
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.