control is perhaps one of the more welcome innovations in XForms, and was in fact back-ported to HTML 5. In XForms 1.0, <output>
was typically determined by the incoming data type, in conjunction with the appearance
attribute. However, it was usually given as a text value with no overt decoration. In XForms 1.1, <output>
now also supports the mediatype
attribute, which in turn takes a mime-type value as an expression.
For instance, if the mediatype is set to image/* and the type of the node given in the ref or bind attribute is xs:anyURI, then this will render the URL (if it points to an appropriate image type) as an image of the width and height specified in the original image. This makes it possible to create interface elements such as lists that include avatar pictures, or icons that are themed based upon some property of the given element or attribute value in the instance.
Additionally, when you set the mediatype for output to "text/html," whenever a CDATA section in a given element contains any HTML markup, then it will be rendered as HTML content (i.e., <i>This</i> is a <b>test</b> will be rendered as "This is a test"). The key to this feature is understanding that such CDATA content is not itself rendered as child nodes, but it rather is only text. Like any other form of output, it's not possible to bind an output element directly to a node that has children (although you can create output using the value attribute).
In those versions of XForms that enable user-defined functions, this capability actually makes it possible to both create live "editors" of markup content on the fly and to generate output via templated functions. This allows you to convert multiple inputs into a report or an SVG graphic, if the browser supports it.
Enhanced Function Set
The core XForms function set was also expanded, solving a few of the thornier issues that XForms 1.0 developers have faced. For instance, XForms 1.1 now natively supports a random()
function that will return an xs:double
value between 0
. This has long been on my personal wish list, as it enables building applications such as quizzes where item and question order are randomized. In general, it makes it easier to create "simulator" type apps and games.
The power() function also extends the math set, in this case by giving you the capability of evaluating power relationships (i.e., ab). Thus, you could build a simple Pythagoras machine that would generate hypotenuses. If you have three siblings (a, b, and c) that represent the three sides of a right triangle, then you can determine the c side from a and b as follows: <xf:output ref="c" value="power((power(a,2)+(power(b,2),1/2)"/> , which calculates the expression (a² + b²)½.
The compare() function is used to compare two strings and determine from them in what order they would appear, using Unicode code-point collations (sorting by language). This is used primarily to create sorting algorithms.
The digest() and hmac() functions are used to create hashes from strings. Such hashes are used primarily in cryptographic routines, including the creation of authentication keys for posting web content via SSL forms in a secure manner.
A welcome addition is the introduction of a number of new date math functions:
- local-date() and local-dateTime(): The local:date() and local-dateTime() functions retrieve the date and extended datetime values for the current moment, reading the now() function and adjusting for timezone.
- seconds-to-dateTime() and days-to-date(): The seconds-to-dateTime() and days-to-date() functions take a delta value (the number of seconds or days, as appropriate) from the current date to determine the new date. Thus, if you wanted to know the date 30 days from the current day, you'd use days-to-date(30).
- adjust-dateTime-to-timezone(): The adjust-dateTime-to-timezone() function takes a date with a given timezone (or Greenwich Mean Time if no timezone is given) and converts it into the local data and time.