1.1 --- a/docs/template-design.html Sat Nov 05 01:43:09 2005 +0000
1.2 +++ b/docs/template-design.html Sat Nov 05 01:44:21 2005 +0000
1.3 @@ -21,14 +21,14 @@
1.4 representing the information in the user interface. The most common
1.5 medium for presentation is HTML and its derivatives, and we consider
1.6 here the different HTML elements available to present different
1.7 -"patterns" in a document structure.</p><h3>General Template Structure</h3><p>Templates based on HTML usually have the following general structure:</p><pre><?xml version="1.0"?><br /><html xmlns="http://www.w3.org/1999/xhtml"<br /> xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"><br /><head><br /> <title>Some title</title><br /></head><br /><body template:element="structure"><br /><br /><!-- The interesting part goes here... --><br /><br /></body><br /></html></pre><p>Since we will want to edit the data produced by such a template, an HTML <code>form</code> element is usually necessary within the <code>body</code> element:</p><pre><body template:element="structure"><br /><form action="" method="POST"><br /><br /><!-- The interesting part goes here... --><br /><br /></form><br /></body></pre><p>We usually define the <code>method</code> as <code>POST</code> in order to minimise complications with handling the data in the XSLForms toolkit.</p><h3>Static Elements</h3><p>Static
1.8 +"patterns" in a document structure.</p><h3>General Template Structure</h3><p>Templates based on HTML usually have the following general structure:</p><pre><?xml version="1.0"?><br /><html xmlns="http://www.w3.org/1999/xhtml"<br /> xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"><br /><head><br /> <title>Some title</title><br /></head><br /><body template:element="structure"><br /><br /><!-- The interesting part goes here... --><br /><br /></body><br /></html></pre><p>Since we will want to edit the data produced by such a template, an HTML <code>form</code> element is usually necessary within the <code>body</code> element:</p><pre><body template:element="structure"><br /><form action="" method="POST"><br /><br /><!-- The interesting part goes here... --><br /><br /></form><br /></body></pre><p>We usually define the <code>method</code> as <code>post</code> in order to minimise complications with handling the data in the XSLForms toolkit.</p><h3>Static Elements</h3><p>Static
1.9 elements, as opposed to collection elements, are elements in the
1.10 -document structure which maintain some kind of organisation or grouping
1.11 +form data document structure which maintain some kind of organisation or grouping
1.12 within a document, but whose presence cannot be edited by the user of
1.13 an application. For example, in the <a href="XSLForms-resource.html">"Using the XSLFormsResource API"</a> document the following example is given:</p><pre><div template:element="hard-disks"><br /> <input template:selector-field="add-hard-disk,hard-disk" type="submit" name="..." value="Add hard disk"/><br /> <p template:element="hard-disk"><br /> ...<br /> </p><br /></div></pre><p>Here, the <code>hard-disks</code> element is present to group <code>hard-disk</code>
1.14 elements together. We can insist that elements are treated as static
1.15 elements in the document initialisation process by adding the <code>template:init</code> attribute to the annotated template element:</p><pre><div template:element="hard-disks" template:init="yes"><br /> ...<br /></div></pre><p>See the <a href="reference.html">"Template Attribute Reference"</a> document for more information on the <code>template:init</code> attribute.</p><h3>Collection Elements</h3><p>Collection
1.16 -elements are elements in the document structure which represent a
1.17 +elements are elements in the form data document structure which represent a
1.18 collection of items or objects and whose presence may be edited by the
1.19 user of an application. In the following example, <code>hard-disk</code> elements are collection elements:</p><pre><input template:selector-field="add-hard-disk,hard-disk" type="submit" name="..." value="Add hard disk"/><br /><p template:element="hard-disk"><br /> ...<br /></p></pre><p>Whether
1.20 elements are treated as collection elements in the document
1.21 @@ -45,14 +45,70 @@
1.22 document, selectors provide a means to select elements in collections
1.23 and to request that some operation be performed on those selected
1.24 elements. Two common selector types are those concerning the addition
1.25 -and removal of elements.</p><p>In the collection elements example above, we saw the usage of a selector which could be used to add elements to a document:</p><pre><input template:selector-field="add-hard-disk,hard-disk" type="submit" name="..." value="Add hard disk"/></pre><p>As described in the <a href="XSLForms-resource.html">"Using the XSLFormsResource API"</a> document, the above selector (with the name <code>add-hard-disk</code>)
1.26 +and removal of elements.</p><h4>Selectors as Buttons</h4><p>In the collection elements example above, we saw the usage of a selector which could be used to add elements to a document:</p><pre><input template:selector-field="add-hard-disk,hard-disk" type="submit" name="..." value="Add hard disk"/></pre><p>This would produce the following HTML form control:</p><p><input name="..." value="Add hard disk" type="submit" /> </p><p>As described in the <a href="XSLForms-resource.html">"Using the XSLFormsResource API"</a> document, the above selector (with the name <code>add-hard-disk</code>)
1.27 could be obtained and the associated collection of elements used to
1.28 insert new elements within the specified elements. Similarly, a
1.29 selector which could be used to remove elements from a document could
1.30 -be specified as follows:</p><pre><input template:selector-field="remove-hard-disk" type="submit" name="..." value="Remove hard disk"/></pre><p>Again, such a selector could be obtained and its associated elements removed from the document.</p><h3>Simple Attribute Values</h3><p>A
1.31 +be specified as follows:</p><pre><input template:selector-field="remove-hard-disk" type="submit" name="..." value="Remove hard disk"/></pre><p>This would produce the following HTML form control:</p><p><input name="..." value="Remove hard disk" type="submit" /></p><p>Again, such a selector could be obtained and its associated elements removed from the document.</p><h4>Selectors as Checkboxes</h4><p>Whilst
1.32 +selectors can be modelled conveniently with buttons, since they may
1.33 +cause an immediate update to the form data with feedback from the
1.34 +operation occurring immediately, other form controls can be used to
1.35 +communicate the selection of form data. For example:</p><pre><input template:selector-field="select-hard-disk" type="checkbox" name="..." value="..."/></pre><p>This would produce the following HTML form control:</p><p><input name="..." value="..." type="checkbox" /></p><p>Such
1.36 +a checkbox could be used to mark a particular element in the form data
1.37 +document as being selected, with the application left to determine what
1.38 +kind of operation should be applied to the selection.</p><h3>Attribute Values</h3><p>A
1.39 simple attribute value is defined to be a value, freely editable set in
1.40 -an attribute on some element in a document. For example:</p><pre><element attribute="value"/></pre><p>If we are to permit this value to be edited, we might choose the following template representation:</p><pre><input template:attribute-field="attribute" name="..." value="..." type="text"/></pre><p>Note that <code>element</code> is not declared in the above example, although we could also add such an annotation to the <code>input</code> element (as described in the <a href="reference.html">"Template Attribute Reference"</a> document).</p><h4>Read-only Values</h4><p>Where attribute values are only displayed, we can use non-form HTML elements to display them:</p><pre><span template:attribute-area="attribute">some text to be replaced with the value</span></pre><p>However, if such values are to be retained and submitted again by the user, we also need to include them as hidden elements:</p><pre><input template:attribute-field="attribute" name="..." value="..." type="hidden"/></pre><p>This
1.41 +an attribute on some element in a document. For example, in an XML document:</p><pre><element attribute="value"/></pre><p>The
1.42 +following sections describe ways in which the value can be viewed,
1.43 +edited or changed through the presentation of the attribute in the
1.44 +template.</p><h4>Editable Fields</h4><p>If we are to permit an attribute value to be edited, we might choose the following template representation:</p><pre><input template:attribute-field="attribute" name="..." value="..." type="text"/></pre><p>This would produce the following HTML form control:</p><p><input name="..." value="..." /></p><p>Note
1.45 +that the element on which the attribute is defined is not declared in
1.46 +the above example, although we could also add such an annotation to
1.47 +the <code>input</code> element (as described above and in the <a href="reference.html">"Template Attribute Reference"</a> document).</p><h4>Read-only Values</h4><p>Where attribute values are only displayed, we can use non-form HTML elements to display them:</p><pre><span template:attribute-area="attribute">some text to be replaced with the value</span></pre><p>This would insert the value of the attribute in the document within the defined <code>span</code> template element.</p><h4>Hidden Values</h4><p>Where
1.48 +attribute values are to be retained and submitted again by the
1.49 +user, but probably not edited, we need to include them as hidden
1.50 +elements:</p><pre><input template:attribute-field="attribute" name="..." value="..." type="hidden"/></pre><p>This
1.51 keeps the contents of the document intact, but it should be noted that
1.52 such values are only uneditable in the way they are presented to
1.53 the user, and that a determined user could easily find a way to change
1.54 -such values and send them in to the application.</p></body></html>
1.55 \ No newline at end of file
1.56 +such values and send them in to the application.</p><h4>Checkboxes</h4><p>Sometimes,
1.57 +attributes are used to retain particular values that correspond to a
1.58 +boolean state. Such values can be modelled as follows:</p><pre><input template:attribute-button="attribute,true,checked" name="..." value="..." type="checkbox"/></pre><p>This would produce the following HTML form control:</p><p><input name="..." value="..." type="checkbox" /></p><p>If selected, the checkbox would when submitted cause the attribute to contain the value <code>true</code>
1.59 +in the form data document. Moreover, the presence of the attribute with
1.60 +such a value would cause the checkbox to appear selected when the form
1.61 +data is presented to the user again.</p><h4>Radio Buttons</h4><p>Unlike
1.62 +checkboxes, radio buttons typically offer a means to select a value
1.63 +from a number of alternatives. However, like checkboxes the selected
1.64 +value would be stored on a single attribute in the form data document.
1.65 +For example:</p><pre><input type="radio" template:attribute-button="attribute,some-choice,checked" name="..." value="..." /></pre><p>This would produce the following HTML form control:</p><p><input name="..." value="..." type="radio" /></p><p>If
1.66 +selected, the radio button when submitted would cause the attribute to
1.67 +contain the stated value in the form data document, which would be <code>some-choice</code>
1.68 +for the button in the above example. Should a different button
1.69 +associated with the same attribute be pressed, the value stated in the
1.70 +definition of that button would be stored in the attribute. Like the
1.71 +checkbox, the selected radio button would remain selected when the form
1.72 +data is presented to the user again.</p><h3>Attributes Set from Lists of Choices</h3><p>Certain
1.73 +attributes may have a list of acceptable values associated with them,
1.74 +and whilst such attributes typically reside in the form data document
1.75 +carrying a single, currently set value, the representation of the
1.76 +document processed by the template must somehow incorporate the list of
1.77 +acceptable values; this was covered in the <a href="multiple.html">"Creating Applications: Adding Multiple-Choice Fields and Values"</a> document, and involved adding new elements, each carrying a single acceptable value for the attribute concerned.</p><h4>Single Selection Menus</h4><p>In
1.78 +certain situations, it makes more sense to present acceptable values
1.79 +for an attribute in a menu-like representation in the final output
1.80 +presented to the user. With the element on which the attribute resides
1.81 +now containing a list of sub-elements with each carrying an acceptable
1.82 +value in an attribute, a form control can be defined as follows:</p><pre><select template:multiple-choice-field="-,attribute" name="..."><br /> <option template:multiple-choice-value="element-enum,value,selected" value="..."></option><br /></select></pre><p>This would produce the following HTML form control:</p><p><select name="..."><option>First</option><option>Second</option><option>Third</option></select></p><p>Note that the element on which the attribute is defined is not declared
1.83 +in the above example, although we could modify the <code>template:multiple-choice-field</code> annotation on
1.84 +the <code>select</code> element (as described in the <a href="reference.html">"Template Attribute Reference"</a> document) and replace the <code>-</code> with a name such as <code>element</code>.</p><h4>Multiple Selection Lists</h4><p>In
1.85 +other situations, where many values can be chosen, a single attribute
1.86 +on a single element is not sufficient to hold all such values.
1.87 +Consequently, a collection of elements is employed, each with an
1.88 +attribute defined to hold a single value. With each value-bearing
1.89 +element now containing a list of sub-elements with each carrying
1.90 +an acceptable
1.91 +value in an attribute, a form control can be defined as follows:</p><pre><select name="..." template:multiple-choice-list-field="-,element-enum,attribute" multiple="multiple"><br /> <option template:multiple-choice-list-value="element-enum,value,selected" value="..."></option><br /></select></pre><p>This would produce the following HTML form control:</p><p><select multiple="multiple" name="..."><option>First</option><option>Second</option><option>Third</option></select></p><p>Note that unlike the single selection menu example, an additional parameter is present in the <code>template:multiple-choice-list-field</code> annotation, but the first parameter is given as the placeholder value <code>-</code> (and is regarded as not having been stated). However, had the first parameter been stated (as opposed to being given as <code>-</code>)
1.92 +the consequence would merely have been that upon submission of the
1.93 +form, the elements in the collection would have been enclosed
1.94 +within a single named element. In the above example, we assume that a
1.95 +suitable element has already been defined in a template element and
1.96 +that the above <code>select</code> element resides within that template element, thus providing the necessary enclosure (as recommended in the <a href="advice.html">"Creating Applications: Recommendations and Advice"</a> document).</p></body></html>
1.97 \ No newline at end of file