Adding a feed
What is it?
Remember, the name of this application is Bookcast, which lets suggest that we can expose the list of books as a feed of some sort. Here, you will use the [Atom Syndication Format][28] (or Atom in short). Atom is a format very much like RSS but it has been standardized by IETF and is much cleaner than RSS (note that there are at least 6 different versions of RSS). Atom is now supported by most feed readers.
An atom feed looks like this (example from the Atom specification):
It would be nice if you could use XForms to produce such a format, and in fact in theory this is possible, but Orbeon Forms currently only supports XForms embedded within XHTML. So here you will use XSLT instead. XSLT is an XML transformation language, which can also be used as an XML template language.
But first, it's time to introduce the Model-View-Controller (MVC) support in the page flow. Consider the following page flow declaration:
Notice how, instead of an XHTML page view (view.xhtml
), you now use:
A page model, called
atom.xpl
. This page model has an*.xpl
extension, which tells you that it contains an XML pipeline.A page view, called
view.xsl
. This page view has an*.xsl
extension, which tells you that it contains an XSLT stylesheet.
So what's the idea behind page models and page views? The idea is to separate the production of the data to display, from the visual formatting of that data. The page model is in charge of the former, and the page view of the latter. In the case of the production of the Atom feed:
The page model is in charge of fetching the data (the
books.xml
document) from the database.The page view formats that data to produce a valid Atom document.
This separation means that you can change how the data is retrieved without changing the formatting part, and the other way around. The Orbeon Forms Page Flow Controller (PFC) automatically connects page model and page view.
Consider the page model:
This document contains an XML pipeline described in a language called XPL (XML Pipeline Language). An XML pipeline language is simply a language for describing operations to be performed on XML documents. Orbeon Forms comes with an implementation of XPL. (Orbeon is currently working at W3C on the standardization of a pipeline language called XProc.)
So what does this pipeline do? It runs a processor called oxf:xforms-submission
, which is a handy component that allows you to perform XForms submissions from XPL. That submission retrieves books.xml
and returns it on the processor's response
output. That output in turn is sent to the data
output of the page model pipeline.
Now look at the page view:
This page view is an XSLT document (notice the xsl:version="2.0"
attribute on the root element). It automatically receives on its main input the document produced by the page model. So if you were to write:
You would get the title of the first book from books.xsl
.
Now this XSLT document does not use many XSLT constructs:
XSLT relies on XPath, like XForms. So you can reuse your knowledge of XPath when writing XSLT.
<xsl:value-of>
outputs the text value returned by the XPath expression on theselect
attribute. It is very similar to<xf:output>
.<xsl:for-each>
iterates over the nodes returned by the XPath expression on theselect
attribute. It is very similar to<xf:repeat>
.The brackets in
<a href="{link}">
mean that the XPath expressionlink
has to be evaluated to produce thehref
attribute.
And that's it! You can now add the entry in page-flow.xml
, add the two files atom.xpl
and atom.xsl
, and point your browser to:
You should see something similar to this, depending on your browser:
To make things even better, add the following to view.xhtml
under the <head>
element:
With this addition, most modern browsers will display a feed icon or an RSS icon, making the feed directly accessible from the main Bookcast page.
You can now try to load the feed into your favorite feed reader! Here is how the Bookcast feed looks in the Mozilla Thunderbird feed reader:
What's next
So far you have seen:
How to setup Orbeon Forms.
How the basic Hello application is organized.
How to build your own application that allows editing and persisting a form.
How to create an Atom feed from form data.
You have now covered a good part of the basics of Orbeon Forms. You can now look at the Orbeon Forms example applications and the rest of the Orbeon Forms documentation!