The template is a central concept in the XSLForms toolkit: each template defines the structure of the XML document information being processed by an application (or a resource within an application), and each template presents that document information in a form readable by an application's users.
The relationship between the defined structure and the template itself is described in the "Creating Applications: Design the Structure of the Form Data" document. Typically, one will have in mind a particular structure to be presented and made editable by the template, and one will begin the template design process with this structure in mind, although the structure definition is likely to be modified by decisions made in the design process and when testing the user interface by using the application itself.
Given a document structure, one has to think about the most suitable ways of representing the information in the user interface. The most common medium for presentation is HTML and its derivatives, and we consider here the different HTML elements available to present different "patterns" in a document structure.
Templates based on HTML usually have the following general structure:
<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:template="http://www.boddie.org.uk/ns/xmltools/template">
<head>
<title>Some title</title>
</head>
<body template:element="structure">
<!-- The interesting part goes here... -->
</body>
</html>
Since we will want to edit the data produced by such a template, an HTML form
element is usually necessary within the body
element:
<body template:element="structure">
<form action="" method="POST">
<!-- The interesting part goes here... -->
</form>
</body>
We usually define the method
as POST
in order to minimise complications with handling the data in the XSLForms toolkit.
Static elements, as opposed to collection elements, are elements in the document structure which maintain some kind of organisation or grouping within a document, but whose presence cannot be edited by the user of an application. For example, in the "Using the XSLFormsResource API" document the following example is given:
<div template:element="hard-disks">
<input template:selector-field="add-hard-disk,hard-disk" type="submit" name="..." value="Add hard disk"/>
<p template:element="hard-disk">
...
</p>
</div>
Here, the hard-disks
element is present to group hard-disk
elements together. We can insist that elements are treated as static
elements in the document initialisation process by adding the template:init
attribute to the annotated template element:
<div template:element="hard-disks" template:init="yes">
...
</div>
See the "Template Attribute Reference" document for more information on the template:init
attribute.
Collection
elements are elements in the document structure which represent a
collection of items or objects and whose presence may be edited by the
user of an application. In the following example, hard-disk
elements are collection elements:
<input template:selector-field="add-hard-disk,hard-disk" type="submit" name="..." value="Add hard disk"/>
<p template:element="hard-disk">
...
</p>
Whether
elements are treated as collection elements in the document
initialisation process depends on the presence or absence of the template:init
attribute on the annotated template element: if the template:init
attribute is present, the value of that attribute will determine whether such elements (named in the template:element
attribute) will be created automatically (and thus behave like static
elements) or created dynamically (and thus behave like collection
elements); if the template:init
attribute is absent,
the way such elements are treated will depend on other factors, notably
the presence of selectors referring to such elements.
In the above example, the selector field (see below and in the "Template Attribute Reference" document for more details) mentions the document structure's hard-disk
element; thus, the element is treated as a collection. If we did not
have such a selector in the template, we could also have used a template:init
attribute to have the same effect:
<p template:element="hard-disk" template:init="no">
...
</p>
Generally, collection elements do have selector fields providing operations on the collection, and so the extra annotation is not usually necessary.
As described in the "Creating Applications: Add Selectors" document, selectors provide a means to select elements in collections and to request that some operation be performed on those selected elements. Two common selector types are those concerning the addition and removal of elements.
In the collection elements example above, we saw the usage of a selector which could be used to add elements to a document:
<input template:selector-field="add-hard-disk,hard-disk" type="submit" name="..." value="Add hard disk"/>
As described in the "Using the XSLFormsResource API" document, the above selector (with the name add-hard-disk
)
could be obtained and the associated collection of elements used to
insert new elements within the specified elements. Similarly, a
selector which could be used to remove elements from a document could
be specified as follows:
<input template:selector-field="remove-hard-disk" type="submit" name="..." value="Remove hard disk"/>
Again, such a selector could be obtained and its associated elements removed from the document.
A simple attribute value is defined to be a value, freely editable set in an attribute on some element in a document. For example:
<element attribute="value"/>
If we are to permit this value to be edited, we might choose the following template representation:
<input template:attribute-field="attribute" name="..." value="..." type="text"/>
Note that element
is not declared in the above example, although we could also add such an annotation to the input
element (as described in the "Template Attribute Reference" document).
Where attribute values are only displayed, we can use non-form HTML elements to display them:
<span template:attribute-area="attribute">some text to be replaced with the value</span>
However, if such values are to be retained and submitted again by the user, we also need to include them as hidden elements:
<input template:attribute-field="attribute" name="..." value="..." type="hidden"/>
This keeps the contents of the document intact, but it should be noted that such values are only uneditable in the way they are presented to the user, and that a determined user could easily find a way to change such values and send them in to the application.