eXforms - extending XForms 1.0

14 December 2006

This version:
http://exforms.org/conditionals.html
Editor:
David Landwehr, exforms.org

Status of this Document

This module defines a set of attributes which can be used on all action to make conditional and looping behavior of the action when invoked. The following is what this modules provides:

Table of Contents

1 Conditional, Looping and Invocation Extension for Actions
    1.1 The Module
    1.2 The exf:if Attribute
    1.3 The exf:while Attribute
    1.4 The exf:iterateAttribute
    1.5 The exf:invoke and exf:invoke-initial Attribute
2 References
    2.1 Normative References

Appendix

A Acknowledgments (Non-Normative)


1 Conditional, Looping and Invocation Extension for Actions

1.1 The Module

This module defines a set of attributes which can be used on all action to make conditional and looping behavior of the action when invoked. The following is what this modules provides:

Iterate the invocation of the action over a node-set
Condition determine if an action should be invoked
Loop the action as long a condition holds true
Invoke an action if a XPath expression signals true. An XPath expression signals true if it boolean state changes from false to true during a xforms-refresh

The attributes defined by this specification has a precedence order which is defined as following:

  1. exf:if conditional attribute

  2. exf:while looping attribute

  3. exf:iterate iterating attribute

The last attributes are called exf:invoke and exf:invoke-initial but has no precedence since these attributes are a triggering mechanism.

Special handling for deferred updates apply for exf:while and exf:iterate so that the entire execution happens in one deferred update's scope. This means that the processing model must not dispatch the xforms-rebuild, xforms-recalculate, xforms-revalidate and xforms-refresh. However it is allowed for the author to explicitly use one of the actions to perform the task if desired.

Note:

Notice that exf:iterate changes the context for the expressions.

The module name to be used for this extension is defined as exf:conloop

1.2 The exf:if Attribute

The exf:if is an [XPath 1.0] expression which is evaluated before an action is executed. The expressions result is converted to a boolean as if converted with the boolean() defined by the [XPath 1.0] specification and if it evaluates to false the action's must not be executed.

Example: how to use exf:if
<xforms:model>
  <xforms:instance>
    <data xmlns="">
      <node selected="false"/>
      <node selected="true"/>
    </data>
  </xforms:instance>
</xforms:model>

<xforms:trigger>
  <xforms:label>Delete the first node if it is selected</xforms:label>
  <xforms:delete nodeset="node" at="1" exf:if="./@selected='true'"/>
</xforms:trigger>

Notice the evaluation scope for the exf:if attribute. It uses the in-scope evaluation context.

1.3 The exf:while Attribute

The exf:whileel> is an [XPath 1.0] expression which is evaluated to a boolean by converting the result as by the boolean() defined by the [XPath 1.0] specification. The attribute is evaluated before the initial execution of the action and if it is true the action is executed. Afterwards it is evaluated again and if it is still true the action is executed once more and so on.

Note:

Notice that the exf:if is evaluated after exf:while is evaluated

Example: how to use exf:while
<xforms:model>
  <xforms:instance>
    <data xmlns="">
      <node selected="true"/>
      <node selected="true"/>
    </data>
  </xforms:instance>
</xforms:model>

<xforms:trigger>
  <xforms:label>Delete all selected</xforms:label>
  <xforms:delete nodeset="node" at="1" exf:while="../node/@selected='true'"/>
</xforms:trigger>

Notice the evaluation scope for the exf:while attribute. It uses the in-scope evaluation context.

1.4 The exf:iterateAttribute

The exf:iterate is an [XPath 1.0] expression which must evaluate to a node-set. The action is executed with each node in the node-set as context. This context replaces the default context set by the [XForms 1.0].

Note:

Notice that the exf:iterate changes the context for exf:if and exf:while. Also notice the exf:iterate is evaluated before any of the two.

Example: how to use exf:iterate
<xforms:model>
  <xforms:instance>
    <data xmlns="">
      <node selected="true"/>
      <node selected="true"/>
    </data>
  </xforms:instance>
</xforms:model>

<xforms:trigger>
  <xforms:label>Delete all selected</xforms:label>
  <xforms:delete nodeset="." at="1" exf:iterate="node[@selected='true']"/>
</xforms:trigger>

Notice the evaluation scope for the delete action

1.5 The exf:invoke and exf:invoke-initial Attribute

The exf:invoke is an [XPath 1.0] expression which is converted to a boolean as by the boolean() from the [XPath 1.0] specification. The expression is evaluated during xforms-refresh as if the expression was a binding expression and if it evaluates from false to true then the action it is placed on is executed.

A helper attribute for exf:invoke is exf:invoke-initial which is of type xsd:boolean. This attribute sets the initial state such that this functionality works initially. If this helper attribute isn't present on the action the initial state is set to true.

Example: how to use exf:invoke
<xforms:model>
  <xforms:instance>
    <data xmlns="">
      <node1>value</node1>
      <node2></node2>
    </data>
  </xforms:instance>
  <!-- Calculate how many times node1's value is set to value -->
  <xforms:setvalue ref="node2" value=".+1" exf:invoke="../node1 = 'value' exf:inoke-initial="false"/>

2 References

2.1 Normative References

XForms 1.0
XForms - Version 1.0, John M. Boyer, David Landwehr, Roland Merrick, T. V. Raman, Micah Dubinko, Leigh L. Klotz, Jr., 2006. W3C Recommendation available at: http://www.w3.org/TR/xforms/.
XML Events
XML Events - An events syntax for XML, Steven Pemberton, T. V. Raman, Shane P. McCarron, 2002. W3C Recommendation available at: http://www.w3.org/TR/xml-events/.
XPath 1.0
XML Path Language (XPath) Version 1.0, James Clark, Steve DeRose, 1999. W3C Recommendation available at: http://www.w3.org/TR/xpath.
XML Schema part 1
XML Schema Part 1: Structures, Henry S. Thompson, David Beech, Murray Maloney, Noah Mendelsohn, 2001. W3C Recommendation available at: http://www.w3.org/TR/xmlschema-1/.
XML Schema part 2
XML Schema Part 2: Datatypes, Paul V. Biron, Ashok Malhotra, 2001. W3C Recommendation available at: http://www.w3.org/TR/xmlschema-2/.
RFC 2119
RFC 2119: Key words for use in RFCs to Indicate Requirement Levels, S. Bradner, 1997. Available at http://www.ietf.org/rfc/rfc2119.txt.

A Acknowledgments (Non-Normative)

eXforms.org would like to thank the following for their contributions in creating the extensions:

  • David Landwehr, exforms.org / SolidApp
  • Kenneth Sklander, picoforms.com
  • Allan Beaufour, beaufour.dk