paulb@118 | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
paulb@118 | 2 | <html xmlns="http://www.w3.org/1999/xhtml"> |
paulb@118 | 3 | <head> |
paulb@118 | 4 | |
paulb@118 | 5 | |
paulb@118 | 6 | <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type" /> |
paulb@118 | 7 | |
paulb@118 | 8 | |
paulb@118 | 9 | |
paulb@118 | 10 | <title>Creating Applications: Add Structure</title> |
paulb@118 | 11 | <meta name="generator" content="amaya 8.1a, see http://www.w3.org/Amaya/" /> |
paulb@118 | 12 | |
paulb@118 | 13 | |
paulb@118 | 14 | <link href="styles.css" rel="stylesheet" type="text/css" /> |
paulb@118 | 15 | </head> |
paulb@118 | 16 | |
paulb@118 | 17 | |
paulb@118 | 18 | <body> |
paulb@118 | 19 | |
paulb@118 | 20 | <h1>Creating Applications: Add Structure</h1> |
paulb@118 | 21 | |
paulb@118 | 22 | <p>During the <a href="design.html">design</a> activity, it was |
paulb@118 | 23 | necessary to consider the structure of the information being presented. |
paulb@118 | 24 | In proper XSLForms templates, we make such structural information |
paulb@118 | 25 | explicit by adding special attributes to the HTML code. Consider the |
paulb@118 | 26 | hierarchy example presented in the previous activity:</p> |
paulb@118 | 27 | <ul> |
paulb@118 | 28 | <li>A list of editable items, each containing...<br /> |
paulb@118 | 29 | <ul> |
paulb@118 | 30 | <li>A list of editable items.</li> |
paulb@118 | 31 | </ul> |
paulb@118 | 32 | </li> |
paulb@118 | 33 | </ul> |
paulb@118 | 34 | <h2>The XSLForms Conceptual Model</h2> |
paulb@118 | 35 | <p>In XSLForms applications form data is processed as XML documents.</p> |
paulb@118 | 36 | <ul> |
paulb@118 | 37 | <li>We start with an initial XML document which is then used together |
paulb@118 | 38 | with a template to produce a Web page that can be understood by a Web |
paulb@118 | 39 | browser, and inside this Web page is a form which is used to collect |
paulb@118 | 40 | information from users of our application.</li> |
paulb@118 | 41 | <li>Upon submission of the form, the form data is processed and appears within our application as an XML document once again.</li> |
paulb@118 | 42 | <li>This newly-received document can be processed, validated, and so |
paulb@118 | 43 | on, and then used to produce another Web page for the users to interact |
paulb@118 | 44 | with.</li> |
paulb@118 | 45 | <li>And so the process repeats itself many times.</li> |
paulb@118 | 46 | </ul> |
paulb@118 | 47 | <p>Therefore, it becomes important to imagine how we would represent |
paulb@118 | 48 | the data described above as an XML document; something like this might |
paulb@118 | 49 | be appropriate:</p> |
paulb@118 | 50 | <pre><?xml version="1.0"?><br /><item value="some value"><br /> <subitem subvalue="some other value"/><br /></item></pre> |
paulb@118 | 51 | <p>Therefore, we must seek to add the following structural information to our HTML code:</p> |
paulb@118 | 52 | <ul> |
paulb@118 | 53 | <li>Each list item is represented by an XML element called "item".</li> |
paulb@118 | 54 | <li>The value of each list item is represented by an XML attribute called "value".</li> |
paulb@118 | 55 | <li>Items within items are represented by XML elements called "subitem".</li> |
paulb@118 | 56 | <li>Each value of these subitems is represented by an XML attribute called "subvalue".</li> |
paulb@118 | 57 | </ul> |
paulb@118 | 58 | <p>What we must do is to find a way to describe how our template will |
paulb@118 | 59 | map onto the form data and present it as a Web page for the purpose of |
paulb@118 | 60 | user interaction.<br /> |
paulb@118 | 61 | </p> |
paulb@118 | 62 | <h2>Annotating the Template</h2> |
paulb@118 | 63 | <p>Taking the HTML example from before, we add special annotations to the template to produce something like this:</p> |
paulb@118 | 64 | <pre><html xmlns="http://www.w3.org/1999/xhtml"<br /> xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"><br /><br /><!-- Template text between the start and the interesting part. --><br /><br /><div template:element="item"><br /> <p><br /> Some item: <input template:attribute="value" name="{template:field-name()}" type="text" value="{$this-value}" /><br /> <input name="remove" type="submit" value="Remove" /><br /> </p><br /> <p><br /> Itself containing more items:<br /> </p><br /> <p template:element="subitem"><br /> Sub-item: <input template:attribute="subvalue" name="{template:field-name()}" type="text" value="{$this-value}" /><br /> <input name="remove2" type="submit" value="Remove" /><br /> </p><br /></div><br /><br /><!-- Template text between the interesting part and the end. --><br /><br /></html></pre> |
paulb@118 | 65 | <p>The following annotations have been added:</p> |
paulb@118 | 66 | <ul> |
paulb@118 | 67 | <li>For elements, the <code>template:element</code> attributes were added to the HTML elements which will be replicated when presenting the final output.</li> |
paulb@118 | 68 | <li>For attributes, the <code>template:attribute</code> attributes were added to the form <code>input</code> elements.</li> |
paulb@118 | 69 | </ul> |
paulb@118 | 70 | <p>In addition, some of the attributes in the original HTML code have been changed:</p> |
paulb@118 | 71 | <ul> |
paulb@118 | 72 | <li>The <code>input</code> elements' <code>name</code> attributes have been redefined to use the special <code>{template:field-name()}</code> value.</li> |
paulb@118 | 73 | <li>The <code>input</code> elements' <code>value</code> attributes have been redefined to use the special <code>{$this-value}</code> value.</li> |
paulb@118 | 74 | </ul> |
paulb@118 | 75 | <p>Whereas the first set of annotations reproduce the desired |
paulb@118 | 76 | structure, the latter modifications are really housekeeping measures to |
paulb@118 | 77 | make sure that the final output contains the correct names and values |
paulb@118 | 78 | for each of the form fields shown to the user.</p> |
paulb@118 | 79 | <div class="WebStack"> |
paulb@118 | 80 | <h3>Basic Template Annotation</h3> |
paulb@118 | 81 | <p>The following special annotations can be used to describe XML document structures in templates:</p> |
paulb@118 | 82 | <dl> |
paulb@118 | 83 | <dt><code>template:element</code></dt> |
paulb@118 | 84 | <dd>This attribute should be added to an element in the template in |
paulb@118 | 85 | order to mark that element and its contents as mapping onto or |
paulb@118 | 86 | representing an element in the XML document version of the |
paulb@118 | 87 | form. In the example, the <code>div</code> element is annotated with this attribute to indicate that it maps onto the <code>item</code> element in the XML document version of the form. It is possible to specify more than one name as the value for a <code>template:element</code> attribute by separating each name with a comma; for example:<br /> |
paulb@118 | 88 | <pre><div template:element="parent,child"><br /> <p>This is a child element in the XML document version of the form.</p><br /></div></pre> |
paulb@118 | 89 | </dd> |
paulb@118 | 90 | <dd>The meaning of this is that the annotated element maps onto all <code>child</code> elements within all <code>parent</code> |
paulb@118 | 91 | elements in the XML document version of the form. In other words, |
paulb@118 | 92 | instead of having to create separate HTML elements in the template for |
paulb@118 | 93 | each XML document element being represented, we can collapse the |
paulb@118 | 94 | annotations into a single <code>template:element</code> attribute on a single HTML element.</dd> |
paulb@118 | 95 | <dt><code>template:attribute</code></dt> |
paulb@118 | 96 | <dd>This attribute should be added to an element in the template in |
paulb@118 | 97 | order to mark that element and its contents as mapping onto or |
paulb@118 | 98 | representing an attribute in the XML document version of the form. |
paulb@118 | 99 | The <code>template:attribute</code> annotation exposes various |
paulb@118 | 100 | special values which are described below - such value insert dynamic |
paulb@118 | 101 | content from the XML document version of the form into the final output |
paulb@118 | 102 | generated from the template.</dd> |
paulb@118 | 103 | <dt><code>{$this-value}</code></dt> |
paulb@118 | 104 | <dd>This special value should be used in HTML attributes where the |
paulb@118 | 105 | value of an attribute from the XML document version of the form is |
paulb@118 | 106 | to be included or presented in the final output. In the example, |
paulb@118 | 107 | the <code>value</code> and <code>subvalue</code> attributes are presented in the <code>value</code> attributes of the HTML <code>input</code> elements in this way.</dd> |
paulb@118 | 108 | <dt><code>{template:field-name()}</code></dt> |
paulb@118 | 109 | <dd>This special value should be used in HTML attributes where the |
paulb@118 | 110 | name of an attribute from the XML document version of the form is to be |
paulb@118 | 111 | included or presented in the final output.</dd> |
paulb@118 | 112 | </dl> |
paulb@118 | 113 | <p>The <a href="reference.html">reference guide</a> provides a complete list of special values for use in template annotations.</p> |
paulb@118 | 114 | </div> |
paulb@118 | 115 | <h2>Adding Selectors</h2> |
paulb@118 | 116 | <p>Whilst the above annotations permit the template to display the data |
paulb@118 | 117 | in XML documents containing form data, the other aspects of the user |
paulb@118 | 118 | interface - the addition and removal of items and subitems - are not |
paulb@118 | 119 | yet modelled in the template.</p> |
paulb@118 | 120 | |
paulb@118 | 121 | </body> |
paulb@118 | 122 | </html> |