eXforms - extending XForms 1.0
14 December 2006
- This version:
- http://exforms.org/template.html
- Editor:
- David Landwehr, exforms.org
Copyright © 2006 eXforms.org
Status of this Document
This module defines a way of associating a DOM fragment to a node and a way of accessing the fragment. The use case is that an author can store information which isn't directly dependent to the instance data but is required for creating a user interface. An example could be an instance representing a mail box and the author want to store a valid from the UI whether a mail was selected. This selected state would then be defined in the template.
Table of Contents
1 Template Extension
1.1 The Module
1.2 The exf:template Attribute
1.3 The exf:template() Function
1.4 The exf:template-owner() Function
1.5 The exf:template-assign Action
2 References
2.1 Normative References
Appendix
A Acknowledgments (Non-Normative)
1 Template Extension
1.1 The Module
This module defines a way of associating a DOM fragment to a node and a way of accessing the fragment. The use case is that an author can store information which isn't directly dependent to the instance data but is required for creating a user interface. An example could be an instance representing a mail box and the author want to store a valid from the UI whether a mail was selected. This selected state would then be defined in the template.
The module name to be used for this extension is defined as exf:template
Note:
Using templates in model item properties is undefined, since this module does not state the order for assigning the templates.
1.2 The exf:template Attribute
The exf:template must be placed on a xforms:bind element and it must be a [XPath 1.0] expression selecting a node-set. The first node in document order from this node-set is used to create the template. The assignment of templates to instance nodes happens during the rebuild processing in the following way:
Every node from the
xforms:bindelement's context is selected for template assignmentIf a selected node hasn't got a template then the
exf:templateis evaluated to locate its template. If the template evaluates to a non-empty node-set then the first node in document order from the node-set is cloned and assigned to the instance node as its template.
Note:
Notice that assignments of templates is preserved across rebuilds. This ensures that information isn't dropped between rebuilds.
<xforms:model>
<xforms:instance id="default">
<emailbox xmlns="">
<email from="contact@exforms.org" subject="How to..."/>
<email from="spam@spammer.com" subject="Buy this for free"/>
</xforms:instance>
<xforms:instance id="template">
<template xmlns="">
<selected>false</selected>
</template>
</xforms:instance>
<xforms:bind nodeset="email" exf:template="instance('template')"/>
</xforms:model>1.3 The exf:template() Function
node-set exf:template(node-set?)
The exf:template-owner returns the template owner for the current context node. If the context node is in a template then the function returns the empty node-set.
<xforms:repeat nodeset="email">
<xforms:input ref="exf:template()/selected">
<xforms:label>Selected?</xforms:label>
<xforms:setvalue ref="ext:template-owner()" value="true" ev:event="click"/>
</xforms:input>
</xforms:repeat>See Example in 1.2 The exf:template Attribute for the model
1.4 The exf:template-owner() Function
node-set exf:template-owner()
The exf:template-owner returns the template owner for the current context node. If the context node is in a template then the function returns the empty node-set.
<xforms:repeat nodeset="email">
<xforms:input ref="exf:template()/selected">
<xforms:label>Selected?</xforms:label>
<xforms:setvalue ref="ext:template-owner()" value="true" ev:event="click"/>
</xforms:input>
</xforms:repeat>See Example in 1.2 The exf:template Attribute for the model
1.5 The exf:template-assign Action
This action (re-)associates or removes a template.
Common Attributes: Must have a single-node binding (defined in XForms).
Attributes:
Special Attributes:
- template
Optional [XPath 1.0] node-set expression to select the node to use for the template.
The processing for exf:template-assign is as follows:
The single-node binding is evaluated to determine which node should be processed
If the attribute template is omitted then the node's associated template is dropped. If the node has no template this action has no effect.
- otherwise
templateis evaluated and if it selects a node-set then the first node in document order from that node-set is cloned and associated as a template. If the node-set was empty then any associated template is removed. If the evaluation produced anything but a node-set then this action has no effect.
<xforms:trigger>
<xforms:label>Make additional selected for the first <email> in template</xforms:label>
<xforms:action ev:event="DOMActivate">
<xforms:insert nodeset="instance('template')/selected" at="1" position="after"/>
<exf:template-assign ref="email" template="instance('template')"/>
</xforms:action>
</xforms:trigger>See Example in 1.2 The exf:template Attribute for the model
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.

