Templates of shadow data
Shadow data
To allow for the association between data and ui-data so that controls can operate on external data sources.
The template Attribute
The template must be placed on a 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:bind element's context is selected for template assignment
- If a selected node hasn't got a template then the exf:template is 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.
Example: how template is used
<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" template="instance('template')"/> </xforms:model>
The template() Function
node-set template(node-set?)
The template returns the template for the current context node. If the context node is in a template then the function returns the empty node-set.
Example: How to use the template() function
<xforms:repeat nodeset="email"> <xforms:input ref="template()/selected"> <xforms:label>Selected?</xforms:label> <xforms:setvalue ref="template-owner()" value="true" ev:event="click"/> </xforms:input> </xforms:repeat>
The template-owner() Function
node-set template-owner()
The 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.
Example: how to use the exf:template-owner()
<xforms:repeat nodeset="email"> <xforms:input ref="template()/selected"> <xforms:label>Selected?</xforms:label> <xforms:setvalue ref="template-owner()" value="true" ev:event="click"/> </xforms:input> </xforms:repeat>
The 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 template is 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.
Example: how to use the ext:template-assign Action
<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"/> <xforms:template-assign ref="email" template="instance('template')"/> </xforms:action> </xforms:trigger>