Introduction to XSLTForms
For more on XForms development, and why it's important, see the article XRX: Simple, Elegant, Disruptive.
The simplest way is to look at some samples online:
To run XSLTForms on your own pages, write standard XForms+XHTML markup, as described in books or numerous web sites, and include a link to the XSLTForms stylesheet at the top of your document, like this:
<?xml-stylesheet href="/path/to/xsltforms.xsl" type="text/xsl"?>
Making it work in XQuery is straightforward. Copy the following, based on hello.xhtml, into an XQuery file named hello.xqy, with the XSLTForms files in a local subdirectory named xsltforms, and run it from a MarkLogic Application Server:
xquery version "1.0-ml"; xdmp:set-response-content-type("application/xml"), <?xml-stylesheet href="xsltforms/xsltforms.xsl" type="text/xsl"?>, <?xsltforms-options debug="yes"?>, <html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms"> <head> <title>Hello World in XForms</title> <xf:model> <xf:instance> <data xmlns=""> <PersonGivenName/> </data> </xf:instance> </xf:model> </head> <body> <xf:input ref="PersonGivenName" incremental="true"> <xf:label>Please enter your first name: </xf:label> </xf:input> <br /> <xf:output value="concat('Hello ', PersonGivenName)"> <xf:label>Output: </xf:label> </xf:output> </body> </html>
This basic form illustrates the incremental mode of input field handling. As you type, the page updates and shows some details of xforms event processing. This is an easy way to check that everything is working properly on your system.
Some things to watch out for:
- As shown in the example above, you may need to deliver the file with the "application/xml" content type for browsers to handle it correctly. If you find the static text of your page displaying but none of the form controls, this is likely the problem.
- If the XML sent or received by the form make use of namespaces, you might need a workaround to work with Firefox, due to an outstanding bug in that browser. More details are available in the project Bugzilla database.
XSLTForms has an active community of supporters that answer questions on the project mailing list. Most beginners' problems have already been solved and message archives contain a wealth of information on solutions. Another thing to try is a recent build from the SVN repository, since in some cases bugs have been fixed subsequent to release.
When it comes to working with structured data, it's hard to beat XForms. New engines like XSLTForms make it easy to include XForms in your application development cycle. Why not give it a try today?