1.1 --- a/docs/structure.html Sun Jul 17 01:07:10 2005 +0000
1.2 +++ b/docs/structure.html Sun Jul 17 19:18:51 2005 +0000
1.3 @@ -2,14 +2,35 @@
1.4 <html xmlns="http://www.w3.org/1999/xhtml">
1.5 <head>
1.6
1.7 +
1.8 +
1.9 +
1.10 +
1.11 +
1.12 +
1.13
1.14 <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type" />
1.15
1.16 +
1.17 +
1.18 +
1.19 +
1.20 +
1.21 +
1.22 +
1.23 +
1.24 +
1.25
1.26
1.27 <title>Creating Applications: Add Structure</title>
1.28 <meta name="generator" content="amaya 8.1a, see http://www.w3.org/Amaya/" />
1.29
1.30 +
1.31 +
1.32 +
1.33 +
1.34 +
1.35 +
1.36
1.37 <link href="styles.css" rel="stylesheet" type="text/css" />
1.38 </head>
1.39 @@ -17,82 +38,209 @@
1.40
1.41 <body>
1.42
1.43 +
1.44 +
1.45 +
1.46 <h1>Creating Applications: Add Structure</h1>
1.47
1.48 +
1.49 +
1.50 +
1.51 <p>During the <a href="design.html">design</a> activity, it was
1.52 necessary to consider the structure of the information being presented.
1.53 In proper XSLForms templates, we make such structural information
1.54 explicit by adding special attributes to the HTML code. Consider the
1.55 hierarchy example presented in the previous activity:</p>
1.56 -<ul>
1.57 - <li>A list of editable items, each containing...<br />
1.58 - <ul>
1.59 - <li>A list of editable items.</li>
1.60 - </ul>
1.61 - </li>
1.62 -</ul>
1.63 -<h2>The XSLForms Conceptual Model</h2>
1.64 -<p>In XSLForms applications form data is processed as XML documents.</p>
1.65 +
1.66 +
1.67 +
1.68 <ul>
1.69 - <li>We start with an initial XML document which is then used together
1.70 -with a template to produce a Web page that can be understood by a Web
1.71 -browser, and inside this Web page is a form which is used to collect
1.72 -information from users of our application.</li>
1.73 - <li>Upon submission of the form, the form data is processed and appears within our application as an XML document once again.</li>
1.74 - <li>This newly-received document can be processed, validated, and so
1.75 -on, and then used to produce another Web page for the users to interact
1.76 -with.</li>
1.77 - <li>And so the process repeats itself many times.</li>
1.78 +
1.79 +
1.80 +
1.81 + <li>A list of editable items, each containing...<br />
1.82 +
1.83 +
1.84 +
1.85 +
1.86 +
1.87 +
1.88 + <ul>
1.89 +
1.90 +
1.91 +
1.92 + <li>A list of editable items.</li>
1.93 +
1.94 +
1.95 +
1.96 +
1.97 +
1.98 +
1.99 + </ul>
1.100 +
1.101 +
1.102 +
1.103 + </li>
1.104 +
1.105 +
1.106 +
1.107 </ul>
1.108 -<p>Therefore, it becomes important to imagine how we would represent
1.109 +
1.110 +<p>
1.111 +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
1.112 the data described above as an XML document; something like this might
1.113 -be appropriate:</p>
1.114 -<pre><?xml version="1.0"?><br /><item value="some value"><br /> <subitem subvalue="some other value"/><br /></item></pre>
1.115 +be appropriate:
1.116 +</p>
1.117 +
1.118 +<pre><?xml version="1.0"?><br /><structure><br /> <item value="some value"><br /> <subitem subvalue="some other value"/><br /> </item><br /></structure></pre>
1.119 +
1.120 +
1.121 +
1.122 <p>Therefore, we must seek to add the following structural information to our HTML code:</p>
1.123 +
1.124 +
1.125 +
1.126 <ul>
1.127 - <li>Each list item is represented by an XML element called "item".</li>
1.128 - <li>The value of each list item is represented by an XML attribute called "value".</li>
1.129 - <li>Items within items are represented by XML elements called "subitem".</li>
1.130 - <li>Each value of these subitems is represented by an XML attribute called "subvalue".</li>
1.131 +
1.132 +
1.133 +
1.134 + <li>Each list item is represented by an XML element called <code>item</code>.</li>
1.135 +
1.136 +
1.137 +
1.138 + <li>The value of each list item is represented by an XML attribute called <code>value</code>.</li>
1.139 +
1.140 +
1.141 +
1.142 + <li>Items within items are represented by XML elements called <code>subitem</code>.</li>
1.143 +
1.144 +
1.145 +
1.146 + <li>Each value of these subitems is represented by an XML attribute called <code>subvalue</code>.</li>
1.147 + <li>Outside all this is a containing <code>structure</code>.</li>
1.148 +
1.149 +
1.150 +
1.151 </ul>
1.152 +
1.153 +
1.154 +
1.155 <p>What we must do is to find a way to describe how our template will
1.156 map onto the form data and present it as a Web page for the purpose of
1.157 user interaction.<br />
1.158 +
1.159 +
1.160 +
1.161 </p>
1.162 +
1.163 +
1.164 +
1.165 <h2>Annotating the Template</h2>
1.166 +
1.167 +
1.168 +
1.169 <p>Taking the HTML example from before, we add special annotations to the template to produce something like this:</p>
1.170 -<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>
1.171 +
1.172 +
1.173 +
1.174 +<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>
1.175 +
1.176 +
1.177 +
1.178 <p>The following annotations have been added:</p>
1.179 +
1.180 +
1.181 +
1.182 <ul>
1.183 +
1.184 +
1.185 +
1.186 <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>
1.187 +
1.188 +
1.189 +
1.190 <li>For attributes, the <code>template:attribute</code> attributes were added to the form <code>input</code> elements.</li>
1.191 +
1.192 +
1.193 +
1.194 </ul>
1.195 +
1.196 +
1.197 +
1.198 <p>In addition, some of the attributes in the original HTML code have been changed:</p>
1.199 +
1.200 +
1.201 +
1.202 <ul>
1.203 +
1.204 +
1.205 +
1.206 <li>The <code>input</code> elements' <code>name</code> attributes have been redefined to use the special <code>{template:field-name()}</code> value.</li>
1.207 +
1.208 +
1.209 +
1.210 <li>The <code>input</code> elements' <code>value</code> attributes have been redefined to use the special <code>{$this-value}</code> value.</li>
1.211 +
1.212 +
1.213 +
1.214 </ul>
1.215 +
1.216 +
1.217 +
1.218 <p>Whereas the first set of annotations reproduce the desired
1.219 structure, the latter modifications are really housekeeping measures to
1.220 make sure that the final output contains the correct names and values
1.221 for each of the form fields shown to the user.</p>
1.222 +
1.223 +
1.224 +
1.225 <div class="WebStack">
1.226 <h3>Basic Template Annotation</h3>
1.227 +
1.228 +
1.229 +
1.230 <p>The following special annotations can be used to describe XML document structures in templates:</p>
1.231 +
1.232 +
1.233 +
1.234 <dl>
1.235 +
1.236 +
1.237 +
1.238 <dt><code>template:element</code></dt>
1.239 +
1.240 +
1.241 +
1.242 <dd>This attribute should be added to an element in the template in
1.243 order to mark that element and its contents as mapping onto or
1.244 representing an element in the XML document version of the
1.245 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 />
1.246 +
1.247 +
1.248 +
1.249 +
1.250 +
1.251 +
1.252 <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>
1.253 +
1.254 +
1.255 +
1.256 </dd>
1.257 +
1.258 +
1.259 +
1.260 <dd>The meaning of this is that the annotated element maps onto all <code>child</code> elements within all <code>parent</code>
1.261 elements in the XML document version of the form. In other words,
1.262 instead of having to create separate HTML elements in the template for
1.263 each XML document element being represented, we can collapse the
1.264 annotations into a single <code>template:element</code> attribute on a single HTML element.</dd>
1.265 +
1.266 +
1.267 +
1.268 <dt><code>template:attribute</code></dt>
1.269 +
1.270 +
1.271 +
1.272 <dd>This attribute should be added to an element in the template in
1.273 order to mark that element and its contents as mapping onto or
1.274 representing an attribute in the XML document version of the form.
1.275 @@ -100,23 +248,51 @@
1.276 special values which are described below - such value insert dynamic
1.277 content from the XML document version of the form into the final output
1.278 generated from the template.</dd>
1.279 +
1.280 +
1.281 +
1.282 <dt><code>{$this-value}</code></dt>
1.283 +
1.284 +
1.285 +
1.286 <dd>This special value should be used in HTML attributes where the
1.287 value of an attribute from the XML document version of the form is
1.288 to be included or presented in the final output. In the example,
1.289 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>
1.290 +
1.291 +
1.292 +
1.293 <dt><code>{template:field-name()}</code></dt>
1.294 +
1.295 +
1.296 +
1.297 <dd>This special value should be used in HTML attributes where the
1.298 name of an attribute from the XML document version of the form is to be
1.299 included or presented in the final output.</dd>
1.300 +
1.301 +
1.302 +
1.303 </dl>
1.304 +
1.305 +
1.306 +
1.307 <p>The <a href="reference.html">reference guide</a> provides a complete list of special values for use in template annotations.</p>
1.308 +
1.309 +
1.310 +
1.311 </div>
1.312 -<h2>Adding Selectors</h2>
1.313 +
1.314 +
1.315 +
1.316 <p>Whilst the above annotations permit the template to display the data
1.317 in XML documents containing form data, the other aspects of the user
1.318 interface - the addition and removal of items and subitems - are not
1.319 -yet modelled in the template.</p>
1.320 +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>
1.321 +
1.322 +
1.323 +
1.324 +
1.325 +
1.326
1.327 </body>
1.328 </html>