1.1 --- a/docs/multivalue.html Thu Jul 21 16:13:09 2005 +0000
1.2 +++ b/docs/multivalue.html Thu Jul 21 16:14:08 2005 +0000
1.3 @@ -20,7 +20,7 @@
1.4 with our items. We revise our <a href="data.html">form data structure</a>
1.5 to
1.6 be the following:</p>
1.7 -<pre><?xml version="1.0"?><br /><structure><br /> <item value="some value"><br /> <types><br /> <type value="some type"/><br /> <type value="some other type"/><br /> </types><br /> <subitem subvalue="some other value"/><br /> </item><br /></structure></pre>
1.8 +<pre><?xml version="1.0"?><br /><structure><br /> <item value="some value"><br /> <type><br /> <type-enum value="some type"/><br /> <type-enum value="some other type"/><br /> </type><br /> <subitem subvalue="some other value"/><br /> </item><br /></structure></pre>
1.9 <h2>Multivalued Fields</h2>
1.10 <p>We shall now take advantage of those HTML form fields which permit
1.11 users to select one
1.12 @@ -45,16 +45,14 @@
1.13 definition of this new list to the template to produce something
1.14 like this:</p>
1.15 <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 /><form action="" method="POST"><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:this-attribute()}" type="text" value="{$this-value}" /><br /> <input name="remove={template:this-element()}" type="submit" value="Remove" /><br /> </p><br /> <span
1.16 - style="font-weight: bold;"><p template:element="types"></span><br /> Item type:<br /> <select template:element="type" name="<span
1.17 - style="font-weight: bold;">{template:list-attribute('value')}</span>" <span
1.18 + style="font-weight: bold;"><p></span><br /> Item type:<br /> <select template:element="type" name="<span
1.19 + style="font-weight: bold;">{template:list-attribute('type-enum', 'value')}</span>" <span
1.20 style="font-weight: bold;">multiple="multiple"</span>><br /> <option template:element="type-enum" template:expr="<span
1.21 style="font-weight: bold;">@value-is-set</span>" template:expr-attr="selected"<br /> template:value="@value" value="{@value}" /><br /> </select><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:this-attribute()}" type="text" value="{$this-value}" /><br /> <input name="remove2={template:this-element()}" type="submit" value="Remove" /><br /> </p><br /> <p><br /> <input name="add2={template:this-element()}" type="submit" value="Add subitem" /><br /> </p><br /></div><br /><p><br /> <input name="add={template:this-element()}" type="submit" value="Add item" /><br /></p><span
1.22 style="font-weight: bold;"><br /><br /></span><!-- Template text between the interesting part and the end. --><br /><br /></form><br /></body><br /></html></pre>
1.23 <p>From the previous <a href="mulitple.html">single-valued case</a>,
1.24 some crucial changes have been made:</p>
1.25 <ol>
1.26 - <li>The paragraph surrounding the field has been annotated to map
1.27 -onto the <code>types</code> element in the form data structure.</li>
1.28 <li>The <code>select</code> element remains mapped onto the <code>type</code>
1.29 element in the form data structure. However, we indicate in the name of
1.30 the <code>select</code>
1.31 @@ -62,8 +60,8 @@
1.32 Instead of mapping onto a single attribute on a single element, the
1.33 value maps onto a single attribute on a single element <span
1.34 style="font-style: italic;">for each value submitted</span>. So for
1.35 -each value selected in the list or menu, a <code>type</code>
1.36 -element is created with the <code>value</code>
1.37 +each value selected in the list or menu, a <code>type-enum</code>
1.38 +element is created (inside the <code>type</code> element) with a <code>value</code>
1.39 attribute containing that value.</li>
1.40 <li>Of course, the <code>select</code> element now has a <code>multiple</code>
1.41 attribute defined to permit multiple value selections.</li>
1.42 @@ -73,48 +71,50 @@
1.43 condition than was used before.</li>
1.44 </ol>
1.45 <h2>Output Structures</h2>
1.46 -<p>Just as in the single-valued case, the revised the form data
1.47 -structure for input does not quite match the structure used by the
1.48 -template. Therefore, we shall define an output form data structure as
1.49 -follows:</p>
1.50 -<pre><?xml version="1.0"?><br /><structure><br /> <item value="some value"><br /> <types><br /> <type><br /> <type-enum value="some type"/><br /> <type-enum value="some other type"/><br /> </type><br /> </types><br /> <subitem subvalue="some other value"/><br /> </item><br /></structure></pre>
1.51 -<p>It is worth noting that the above structure does not define whether
1.52 -many <code>type</code> elements will exist within each <code>types</code>
1.53 -element or whether another mechanism will be used to specify multiple
1.54 -values for each type field.<br />
1.55 +<p>Unlike in the single-valued case, the revised the form data
1.56 +structure for input is almost the same as the structure used by the
1.57 +template. Indeed, the subtle differences cannot be represented in our
1.58 +simplistic presentation of the structure:</p>
1.59 +<pre><?xml version="1.0"?><br /><structure><br /> <item value="some value"><br /> <type><br /> <type-enum value="some type"/><br /> <type-enum value="some other type"/><br /> </type><br /> <subitem subvalue="some other value"/><br /> </item><br /></structure></pre>
1.60 +<p>In fact, the principal difference arises through the number of <code>type-enum</code>
1.61 +elements that occur in the input, representing the values selected by
1.62 +the user, and the number that occur in the output, representing the
1.63 +complete range of values available for selection.
1.64 </p>
1.65 <h3>Presenting the Extra Values</h3>
1.66 <p>In most respects, the presentation of the extra values is the same
1.67 as in the single-valued case. The result of the presentation of the
1.68 -extra values is that the <code>types</code> element in the
1.69 +extra values is that the <code>type</code> element in the
1.70 this example structure fragment...</p>
1.71 -<pre><types><br /> <type><br /> <type-enum value="1"/><br /> <type-enum value="2" value-is-set="true"/><br /> <type-enum value="3" value-is-set="true"/><br /> </type><br /></types></pre>
1.72 +<pre><type><br /> <type-enum value="1"/><br /> <type-enum value="2" value-is-set="true"/><br /> <type-enum value="3" value-is-set="true"/><br /></type><br /></pre>
1.73 <p>...is transformed into something resembling this HTML code:</p>
1.74 -<pre><p><br /> <select name="..." multiple="multiple"><br /> <option value="1">1</option><br /> <option value="2" selected="selected">2</option><br /> <option value="3" selected="selected">3</option><br /> </select><br /></p></pre>
1.75 -<p>Numerous issues arise when considering the above transformation:</p>
1.76 +<pre><select name="..." multiple="multiple"><br /> <option value="1">1</option><br /> <option value="2" selected="selected">2</option><br /> <option value="3" selected="selected">3</option><br /></select><br /></pre>
1.77 +<p>One principal issue arises when considering the above
1.78 +transformation: where does the special <code>value-is-set</code>
1.79 +attribute
1.80 +come from?</p>
1.81 <ul>
1.82 - <li>Were we not supposed to have many <code>type</code> elements?</li>
1.83 - <li>Where does the special <code>value-is-set</code> attribute
1.84 -come from?</li>
1.85 </ul>
1.86 -Here, we have made a strategic decision: with the template as defined
1.87 -above, many <code>type</code> elements would have produced
1.88 -many <code>select</code> elements in the Web form, yet this is not
1.89 -what we want; we need to restrict the number of <code>select</code>
1.90 -elements to one per <code>types</code> element whilst marking the
1.91 -selected values so that they may be displayed appropriately in the list
1.92 -or menu.
1.93 +Here, we have to do two things: to include the full range of possible
1.94 +values so that the user may select from that range, and yet we must
1.95 +remember which values were previously selected. If we just merged
1.96 +the <code>type-enum</code> elements into the <code>type</code>
1.97 +element, we would lose track of which values were selected. Therefore,
1.98 +we need to employ a different strategy in remembering those values than
1.99 +that of assuming that those <code>type-enum</code> elements which
1.100 +are present are those which are selected.
1.101 <h2>Merging and Collecting Values</h2>
1.102 <p>As in the single-valued case, we need to insert the permitted values
1.103 into the form data so that the template may visit the <code>type-enum</code>
1.104 elements and extract those values. However, we have now introduced
1.105 -another task to this activity: to collect the selected values together
1.106 -and to produce a unified <code>type</code> element within
1.107 -each <code>types</code> element. In other words, we want to turn
1.108 +another task to this activity: to mark the selected values in the
1.109 +entire list of <code>type-enum</code> elements in order to
1.110 +distinguish them from the values which are not selected. In other
1.111 +words, we want to turn
1.112 something like this...</p>
1.113 -<pre><types><br /> <type value="2"/><br /> <type value="3"/><br /></types></pre>
1.114 +<pre><type><br /> <type-enum value="2"/><br /> <type-enum value="3"/><br /></type><br /></pre>
1.115 <p>...into something like this:</p>
1.116 -<pre><types><br /> <type><br /> <type-enum value="1"/><br /> <type-enum value="2" value-is-set="true"/><br /> <type-enum value="3" value-is-set="true"/><br /> </type><br /></types></pre>
1.117 +<pre><type><br /> <type-enum value="1"/><br /> <type-enum value="2" value-is-set="true"/><br /> <type-enum value="3" value-is-set="true"/><br /></type><br /></pre>
1.118 Using the same document containing all the permitted values as our
1.119 source of information to be merged into the form data, we can now
1.120 develop a stylesheet which performs the above transformation; this
1.121 @@ -128,24 +128,24 @@
1.122 <ol>
1.123 <li>Copy the element "skeleton" and its attributes so that
1.124 the <code>value</code> attribute is retained.</li>
1.125 - <li>Produce a new <code>types</code> element and process it.</li>
1.126 + <li>Produce a new <code>type</code> element and process it.</li>
1.127 </ol>
1.128 </li>
1.129 - <li>When processing a new <code>types</code> element, do the
1.130 + <li>When processing a new <code>type</code> element, do the
1.131 following:<br />
1.132 <ol>
1.133 - <li>Add a single <code>type</code> element within it.</li>
1.134 <li>Inside this new <code>type</code> element, add the <code>type-enum</code>
1.135 elements from the
1.136 -document containing the values, and if any <code>type</code>
1.137 -elements were found within the <code>item</code> element, specify
1.138 +values document, and if any <code>type-enum</code>
1.139 +elements were found within an existing <code>type</code> element from
1.140 +the form data, specify
1.141 these for the activity.</li>
1.142 </ol>
1.143 </li>
1.144 <li>When adding the <code>type-enum</code> elements, if any of
1.145 them have a <code>value</code> attribute which matches any of the <code>value</code>
1.146 -attributes of the found <code>type</code> elements, set the special
1.147 - <code>value-is-set</code> attribute on that <code>type-enum</code>
1.148 +attributes of the found <code>type-enum</code> elements, set the
1.149 +special <code>value-is-set</code> attribute on that <code>type-enum</code>
1.150 element.</li>
1.151 </ol>
1.152 <p>The stylesheet source code can be found in <code>examples/Common/VerySimple/Resources/structure_multivalue_types.xsl</code>,
1.153 @@ -157,6 +157,9 @@
1.154 others:</p>
1.155 <pre> template_resources = {<br /> "structure" : ("structure_multivalue_template.xhtml", "structure_output.xsl")<br /> }<br /> transform_resources = {<br /> "types" : ["structure_multivalue_types.xsl"]<br /> }<br /></pre>
1.156 <p>With these adjustments, it should now be possible to manipulate the
1.157 -items and subitems whilst specifying multiple type values on each item.</p>
1.158 +items and subitems whilst specifying multiple type values on each item.
1.159 +Note that it may be necessary to remove the old stylesheet for
1.160 +producing output, <code>structure_output.xsl</code>, so that the
1.161 +multivalue version of the template is taken into use.</p>
1.162 </body>
1.163 </html>