XSLTools

docs/structure.html

371:f2710049be3e
2005-11-01 paulb [project @ 2005-11-01 16:47:22 by paulb] Added affected element information to selector-field annotations.
     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">     2 <html xmlns="http://www.w3.org/1999/xhtml"><head>     3   <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type" />     4        5   <title>Creating Applications: Add Structure</title><meta name="generator" content="amaya 8.1a, see http://www.w3.org/Amaya/" />     6   <link href="styles.css" rel="stylesheet" type="text/css" /></head>     7      8 <body>     9 <h1>Creating Applications: Add Structure</h1>    10 <p>Earlier, we defined the <a href="data.html">structure of the form    11 data</a>, and during the <a href="design.html">template design</a>    12 activity, it was    13 necessary to consider this structure information and how it should be    14 presented.    15 In XSLForms templates, we need to explicitly connect such information    16 about the structure of the data to the HTML elements representing it by    17 adding special attributes to the HTML code.</p>    18 <p> Consider the interesting parts of the template side by side with    19 the structure information:</p>    20 <pre style="">&lt;structure&gt;                                   <span style="font-weight: bold;">&lt;body&gt;<br /><br /></span>  &lt;item                                         <span style="font-weight: bold;">&lt;div&gt;</span><br />                                                  &lt;p&gt;<br />        value="some value"&gt;                         Some item: <span style="font-weight: bold;">&lt;input name="value" type="text" value="some value" /&gt;</span><br />                                                    &lt;input name="remove" type="submit" value="Remove" /&gt;<br />                                                  &lt;/p&gt;<br />                                                  &lt;p&gt;<br />                                                    Itself containing more items:<br />                                                  &lt;/p&gt;<br />    &lt;subitem                                      <span style="font-weight: bold;">&lt;p&gt;<br />            </span>&nbsp;subvalue="some other value"/&gt;          Sub-item: <span style="font-weight: bold;">&lt;input name="subvalue" type="text" value="some other value" /&gt;</span><br />                                                    &lt;input name="remove2" type="submit" value="Remove" /&gt;<br />                                                  <span style="font-weight: bold;">&lt;/p&gt;</span><br />                                                  &lt;p&gt;<br />                                                    &lt;input name="add2" type="submit" value="Add subitem" /&gt;<br />                                                  &lt;/p&gt;<br />  &lt;/item&gt;                                       <span style="font-weight: bold;">&lt;/div&gt;</span><br />                                                &lt;p&gt;<br />                                                  &lt;input name="add" type="submit" value="Add item" /&gt;<br />                                                &lt;/p&gt;<br /><br />&lt;/structure&gt;                                  <span style="font-weight: bold;">&lt;/body&gt;</span></pre>    21 <p>To make such connections, we will annotate the&nbsp;HTML code using    22 special attributes and values.</p>    23 <ul>    24 </ul>    25 <h2>Annotating the Template</h2>    26 <p>Taking the template extract from above, we add special annotations    27 to produce something like this:</p>    28 <pre style="">&lt;structure&gt;                                   &lt;body <span style="font-weight: bold;">template:element="structure"</span>&gt;<br /><br />  &lt;item                                         &lt;div <span style="font-weight: bold;">template:element="item"</span>&gt;<br />                                                  &lt;p&gt;<br />        value="some value"&gt;                         Some item: &lt;input <span style="font-weight: bold;">template:attribute-field="value"</span> name="<span style="font-weight: bold;">...</span>" type="text" value="<span style="font-weight: bold;">...</span>" /&gt;<br />                                                    &lt;input name="remove" type="submit" value="Remove" /&gt;<br />                                                  &lt;/p&gt;<br />                                                  &lt;p&gt;<br />                                                    Itself containing more items:<br />                                                  &lt;/p&gt;<br />    &lt;subitem                                      &lt;p <span style="font-weight: bold;">template:element="subitem"</span>&gt;<br />            &nbsp;subvalue="some other value"/&gt;          Sub-item: &lt;input <span style="font-weight: bold;">template:attribute-field="subvalue"</span> name="<span style="font-weight: bold;">...</span>" type="text" value="<span style="font-weight: bold;">...</span>" /&gt;<br />                                                    &lt;input name="remove2" type="submit" value="Remove" /&gt;<br />                                                  &lt;/p&gt;<br />                                                  &lt;p&gt;<br />                                                    &lt;input name="add2" type="submit" value="Add subitem" /&gt;<br />                                                  &lt;/p&gt;<br />  &lt;/item&gt;                                       &lt;/div&gt;<br />                                                &lt;p&gt;<br />                                                  &lt;input name="add" type="submit" value="Add item" /&gt;<br />                                                &lt;/p&gt;<br /><br />&lt;/structure&gt;                                  &lt;/body&gt;</pre>    29 <p style="">    30 The following annotations have been added:</p>    31 <ul>    32   <li>For elements in the structure,&nbsp;<code>template:element</code>    33 attributes have been added to the corresponding HTML elements in the    34 template.</li>    35   <li>For attributes in the structure,&nbsp;<code>template:attribute-field</code>    36 attributes have been added to the corresponding&nbsp;HTML&nbsp;elements    37 in the template.</li>    38 </ul>    39 <p>Note how the&nbsp;<code>name</code> and&nbsp;<code>value</code> attributes have had their contents replaced with&nbsp;<code>...</code>;    40 we do this to keep Web page editors happy, and in the final output    41 these attributes will be replaced with those which model the underlying    42 document correctly.</p>    43 <h2>Completing the Template</h2>    44 <p>The template in full should now look something like this:</p>    45 <pre>&lt;?xml version="1.0"?&gt;<br />&lt;html xmlns="http://www.w3.org/1999/xhtml"<br />      <span style="font-weight: bold;">xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"</span>&gt;<br />&lt;head&gt;<br />  &lt;title&gt;Example&lt;/title&gt;<br />&lt;/head&gt;<br />&lt;body template:element="structure"&gt;<br />&lt;form action="" method="POST"&gt;<br /><br />&lt;!-- Template text between the start and the interesting part. --&gt;<br /><br />&lt;div template:element="item"&gt;<br />  &lt;p&gt;<br />    Some item: &lt;input template:attribute-field="value" name="..." type="text" value="..." /&gt;<br />    &lt;input name="remove" type="submit" value="Remove" /&gt;<br />  &lt;/p&gt;<br />  &lt;p&gt;<br />    Itself containing more items:<br />  &lt;/p&gt;<br />  &lt;p template:element="subitem"&gt;<br />    Sub-item: &lt;input template:attribute-field="subvalue" name="..." type="text" value="..." /&gt;<br />    &lt;input name="remove2" type="submit" value="Remove" /&gt;<br />  &lt;/p&gt;<br />  &lt;p&gt;<br />    &lt;input name="add2" type="submit" value="Add subitem" /&gt;<br />  &lt;/p&gt;<br />&lt;/div&gt;<br />&lt;p&gt;<br />  &lt;input name="add" type="submit" value="Add item" /&gt;<br />&lt;/p&gt;<br /><br />&lt;!-- Template text between the interesting part and the end. --&gt;<br /><br />&lt;/form&gt;<br />&lt;/body&gt;<br />&lt;/html&gt;</pre>    46 <p>Note also that a namespace declaration is required for the&nbsp;<code>template</code>    47 attributes, and it is usually best to put this declaration on the    48 top-level&nbsp;<code>html</code> element in the template, as shown in    49 the above example code.</p>    50 <p>Whilst the above annotations permit the template to display the data    51 in XML documents containing form data, the other aspects of the user    52 interface - the addition and removal of items and subitems - are not    53 yet fully modelled in the template. These things will be added to the    54 template as&nbsp;<a href="selectors.html">selectors</a> as part of the    55 next activity in the development <a href="overview.html">process</a>.</p>    56 </body></html>