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@119 | 5 | |
paulb@119 | 6 | |
paulb@119 | 7 | |
paulb@119 | 8 | |
paulb@119 | 9 | |
paulb@119 | 10 | |
paulb@118 | 11 | |
paulb@118 | 12 | <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type" /> |
paulb@118 | 13 | |
paulb@119 | 14 | |
paulb@119 | 15 | |
paulb@119 | 16 | |
paulb@119 | 17 | |
paulb@119 | 18 | |
paulb@119 | 19 | |
paulb@119 | 20 | |
paulb@119 | 21 | |
paulb@119 | 22 | |
paulb@118 | 23 | |
paulb@118 | 24 | |
paulb@118 | 25 | <title>Creating Applications: Add Structure</title> |
paulb@118 | 26 | <meta name="generator" content="amaya 8.1a, see http://www.w3.org/Amaya/" /> |
paulb@118 | 27 | |
paulb@119 | 28 | |
paulb@119 | 29 | |
paulb@119 | 30 | |
paulb@119 | 31 | |
paulb@119 | 32 | |
paulb@119 | 33 | |
paulb@118 | 34 | |
paulb@118 | 35 | <link href="styles.css" rel="stylesheet" type="text/css" /> |
paulb@118 | 36 | </head> |
paulb@118 | 37 | |
paulb@118 | 38 | |
paulb@118 | 39 | <body> |
paulb@118 | 40 | |
paulb@119 | 41 | |
paulb@119 | 42 | |
paulb@119 | 43 | |
paulb@118 | 44 | <h1>Creating Applications: Add Structure</h1> |
paulb@118 | 45 | |
paulb@119 | 46 | |
paulb@119 | 47 | |
paulb@119 | 48 | |
paulb@118 | 49 | <p>During the <a href="design.html">design</a> activity, it was |
paulb@118 | 50 | necessary to consider the structure of the information being presented. |
paulb@118 | 51 | In proper XSLForms templates, we make such structural information |
paulb@118 | 52 | explicit by adding special attributes to the HTML code. Consider the |
paulb@118 | 53 | hierarchy example presented in the previous activity:</p> |
paulb@119 | 54 | |
paulb@119 | 55 | |
paulb@119 | 56 | |
paulb@118 | 57 | <ul> |
paulb@119 | 58 | |
paulb@119 | 59 | |
paulb@119 | 60 | |
paulb@119 | 61 | <li>A list of editable items, each containing...<br /> |
paulb@119 | 62 | |
paulb@119 | 63 | |
paulb@119 | 64 | |
paulb@119 | 65 | |
paulb@119 | 66 | |
paulb@119 | 67 | |
paulb@119 | 68 | <ul> |
paulb@119 | 69 | |
paulb@119 | 70 | |
paulb@119 | 71 | |
paulb@119 | 72 | <li>A list of editable items.</li> |
paulb@119 | 73 | |
paulb@119 | 74 | |
paulb@119 | 75 | |
paulb@119 | 76 | |
paulb@119 | 77 | |
paulb@119 | 78 | |
paulb@119 | 79 | </ul> |
paulb@119 | 80 | |
paulb@119 | 81 | |
paulb@119 | 82 | |
paulb@119 | 83 | </li> |
paulb@119 | 84 | |
paulb@119 | 85 | |
paulb@119 | 86 | |
paulb@118 | 87 | </ul> |
paulb@119 | 88 | |
paulb@119 | 89 | <p> |
paulb@119 | 90 | Since XSLForms is all about the processing of <a href="model.html">form data as simple XML documents</a>, it becomes important to imagine how we would represent |
paulb@118 | 91 | the data described above as an XML document; something like this might |
paulb@119 | 92 | be appropriate: |
paulb@119 | 93 | </p> |
paulb@119 | 94 | |
paulb@119 | 95 | <pre><?xml version="1.0"?><br /><structure><br /> <item value="some value"><br /> <subitem subvalue="some other value"/><br /> </item><br /></structure></pre> |
paulb@119 | 96 | |
paulb@119 | 97 | |
paulb@119 | 98 | |
paulb@118 | 99 | <p>Therefore, we must seek to add the following structural information to our HTML code:</p> |
paulb@119 | 100 | |
paulb@119 | 101 | |
paulb@119 | 102 | |
paulb@118 | 103 | <ul> |
paulb@119 | 104 | |
paulb@119 | 105 | |
paulb@119 | 106 | |
paulb@119 | 107 | <li>Each list item is represented by an XML element called <code>item</code>.</li> |
paulb@119 | 108 | |
paulb@119 | 109 | |
paulb@119 | 110 | |
paulb@119 | 111 | <li>The value of each list item is represented by an XML attribute called <code>value</code>.</li> |
paulb@119 | 112 | |
paulb@119 | 113 | |
paulb@119 | 114 | |
paulb@119 | 115 | <li>Items within items are represented by XML elements called <code>subitem</code>.</li> |
paulb@119 | 116 | |
paulb@119 | 117 | |
paulb@119 | 118 | |
paulb@119 | 119 | <li>Each value of these subitems is represented by an XML attribute called <code>subvalue</code>.</li> |
paulb@119 | 120 | <li>Outside all this is a containing <code>structure</code>.</li> |
paulb@119 | 121 | |
paulb@119 | 122 | |
paulb@119 | 123 | |
paulb@118 | 124 | </ul> |
paulb@119 | 125 | |
paulb@119 | 126 | |
paulb@119 | 127 | |
paulb@118 | 128 | <p>What we must do is to find a way to describe how our template will |
paulb@118 | 129 | map onto the form data and present it as a Web page for the purpose of |
paulb@118 | 130 | user interaction.<br /> |
paulb@119 | 131 | |
paulb@119 | 132 | |
paulb@119 | 133 | |
paulb@118 | 134 | </p> |
paulb@119 | 135 | |
paulb@119 | 136 | |
paulb@119 | 137 | |
paulb@118 | 138 | <h2>Annotating the Template</h2> |
paulb@119 | 139 | |
paulb@119 | 140 | |
paulb@119 | 141 | |
paulb@118 | 142 | <p>Taking the HTML example from before, we add special annotations to the template to produce something like this:</p> |
paulb@119 | 143 | |
paulb@119 | 144 | |
paulb@119 | 145 | |
paulb@119 | 146 | <pre><html xmlns="http://www.w3.org/1999/xhtml"<br /> xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"><br /><head><br /> <title>Example</title><br /></head><br /><body template:element="structure"><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 /></body><br /></html></pre> |
paulb@119 | 147 | |
paulb@119 | 148 | |
paulb@119 | 149 | |
paulb@118 | 150 | <p>The following annotations have been added:</p> |
paulb@119 | 151 | |
paulb@119 | 152 | |
paulb@119 | 153 | |
paulb@118 | 154 | <ul> |
paulb@119 | 155 | |
paulb@119 | 156 | |
paulb@119 | 157 | |
paulb@118 | 158 | <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@119 | 159 | |
paulb@119 | 160 | |
paulb@119 | 161 | |
paulb@118 | 162 | <li>For attributes, the <code>template:attribute</code> attributes were added to the form <code>input</code> elements.</li> |
paulb@119 | 163 | |
paulb@119 | 164 | |
paulb@119 | 165 | |
paulb@118 | 166 | </ul> |
paulb@119 | 167 | |
paulb@119 | 168 | |
paulb@119 | 169 | |
paulb@118 | 170 | <p>In addition, some of the attributes in the original HTML code have been changed:</p> |
paulb@119 | 171 | |
paulb@119 | 172 | |
paulb@119 | 173 | |
paulb@118 | 174 | <ul> |
paulb@119 | 175 | |
paulb@119 | 176 | |
paulb@119 | 177 | |
paulb@118 | 178 | <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@119 | 179 | |
paulb@119 | 180 | |
paulb@119 | 181 | |
paulb@118 | 182 | <li>The <code>input</code> elements' <code>value</code> attributes have been redefined to use the special <code>{$this-value}</code> value.</li> |
paulb@119 | 183 | |
paulb@119 | 184 | |
paulb@119 | 185 | |
paulb@118 | 186 | </ul> |
paulb@119 | 187 | |
paulb@119 | 188 | |
paulb@119 | 189 | |
paulb@118 | 190 | <p>Whereas the first set of annotations reproduce the desired |
paulb@118 | 191 | structure, the latter modifications are really housekeeping measures to |
paulb@118 | 192 | make sure that the final output contains the correct names and values |
paulb@118 | 193 | for each of the form fields shown to the user.</p> |
paulb@119 | 194 | |
paulb@119 | 195 | |
paulb@119 | 196 | |
paulb@118 | 197 | <div class="WebStack"> |
paulb@118 | 198 | <h3>Basic Template Annotation</h3> |
paulb@119 | 199 | |
paulb@119 | 200 | |
paulb@119 | 201 | |
paulb@118 | 202 | <p>The following special annotations can be used to describe XML document structures in templates:</p> |
paulb@119 | 203 | |
paulb@119 | 204 | |
paulb@119 | 205 | |
paulb@118 | 206 | <dl> |
paulb@119 | 207 | |
paulb@119 | 208 | |
paulb@119 | 209 | |
paulb@118 | 210 | <dt><code>template:element</code></dt> |
paulb@119 | 211 | |
paulb@119 | 212 | |
paulb@119 | 213 | |
paulb@118 | 214 | <dd>This attribute should be added to an element in the template in |
paulb@118 | 215 | order to mark that element and its contents as mapping onto or |
paulb@118 | 216 | representing an element in the XML document version of the |
paulb@118 | 217 | 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@119 | 218 | |
paulb@119 | 219 | |
paulb@119 | 220 | |
paulb@119 | 221 | |
paulb@119 | 222 | |
paulb@119 | 223 | |
paulb@118 | 224 | <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@119 | 225 | |
paulb@119 | 226 | |
paulb@119 | 227 | |
paulb@118 | 228 | </dd> |
paulb@119 | 229 | |
paulb@119 | 230 | |
paulb@119 | 231 | |
paulb@118 | 232 | <dd>The meaning of this is that the annotated element maps onto all <code>child</code> elements within all <code>parent</code> |
paulb@118 | 233 | elements in the XML document version of the form. In other words, |
paulb@118 | 234 | instead of having to create separate HTML elements in the template for |
paulb@118 | 235 | each XML document element being represented, we can collapse the |
paulb@118 | 236 | annotations into a single <code>template:element</code> attribute on a single HTML element.</dd> |
paulb@119 | 237 | |
paulb@119 | 238 | |
paulb@119 | 239 | |
paulb@118 | 240 | <dt><code>template:attribute</code></dt> |
paulb@119 | 241 | |
paulb@119 | 242 | |
paulb@119 | 243 | |
paulb@118 | 244 | <dd>This attribute should be added to an element in the template in |
paulb@118 | 245 | order to mark that element and its contents as mapping onto or |
paulb@118 | 246 | representing an attribute in the XML document version of the form. |
paulb@118 | 247 | The <code>template:attribute</code> annotation exposes various |
paulb@118 | 248 | special values which are described below - such value insert dynamic |
paulb@118 | 249 | content from the XML document version of the form into the final output |
paulb@118 | 250 | generated from the template.</dd> |
paulb@119 | 251 | |
paulb@119 | 252 | |
paulb@119 | 253 | |
paulb@118 | 254 | <dt><code>{$this-value}</code></dt> |
paulb@119 | 255 | |
paulb@119 | 256 | |
paulb@119 | 257 | |
paulb@118 | 258 | <dd>This special value should be used in HTML attributes where the |
paulb@118 | 259 | value of an attribute from the XML document version of the form is |
paulb@118 | 260 | to be included or presented in the final output. In the example, |
paulb@118 | 261 | 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@119 | 262 | |
paulb@119 | 263 | |
paulb@119 | 264 | |
paulb@118 | 265 | <dt><code>{template:field-name()}</code></dt> |
paulb@119 | 266 | |
paulb@119 | 267 | |
paulb@119 | 268 | |
paulb@118 | 269 | <dd>This special value should be used in HTML attributes where the |
paulb@118 | 270 | name of an attribute from the XML document version of the form is to be |
paulb@118 | 271 | included or presented in the final output.</dd> |
paulb@119 | 272 | |
paulb@119 | 273 | |
paulb@119 | 274 | |
paulb@118 | 275 | </dl> |
paulb@119 | 276 | |
paulb@119 | 277 | |
paulb@119 | 278 | |
paulb@118 | 279 | <p>The <a href="reference.html">reference guide</a> provides a complete list of special values for use in template annotations.</p> |
paulb@119 | 280 | |
paulb@119 | 281 | |
paulb@119 | 282 | |
paulb@118 | 283 | </div> |
paulb@119 | 284 | |
paulb@119 | 285 | |
paulb@119 | 286 | |
paulb@118 | 287 | <p>Whilst the above annotations permit the template to display the data |
paulb@118 | 288 | in XML documents containing form data, the other aspects of the user |
paulb@118 | 289 | interface - the addition and removal of items and subitems - are not |
paulb@119 | 290 | yet modelled in the template. These things will be added to the template as <a href="selectors.html">selectors</a> as part of the next activity in the development <a href="overview.html">process</a>.</p> |
paulb@119 | 291 | |
paulb@119 | 292 | |
paulb@119 | 293 | |
paulb@119 | 294 | |
paulb@119 | 295 | |
paulb@118 | 296 | |
paulb@118 | 297 | </body> |
paulb@118 | 298 | </html> |