paulb@119 | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
paulb@119 | 2 | <html xmlns="http://www.w3.org/1999/xhtml"> |
paulb@119 | 3 | <head> |
paulb@119 | 4 | |
paulb@119 | 5 | |
paulb@119 | 6 | |
paulb@119 | 7 | |
paulb@119 | 8 | |
paulb@119 | 9 | |
paulb@119 | 10 | |
paulb@119 | 11 | |
paulb@119 | 12 | <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type" /> |
paulb@119 | 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@119 | 23 | |
paulb@119 | 24 | |
paulb@119 | 25 | <title>Creating Applications: Add Selectors</title> |
paulb@119 | 26 | <meta name="generator" content="amaya 8.1a, see http://www.w3.org/Amaya/" /> |
paulb@119 | 27 | |
paulb@119 | 28 | |
paulb@119 | 29 | |
paulb@119 | 30 | |
paulb@119 | 31 | |
paulb@119 | 32 | |
paulb@119 | 33 | |
paulb@119 | 34 | |
paulb@119 | 35 | <link href="styles.css" rel="stylesheet" type="text/css" /> |
paulb@119 | 36 | </head> |
paulb@119 | 37 | |
paulb@119 | 38 | |
paulb@119 | 39 | <body> |
paulb@119 | 40 | |
paulb@119 | 41 | |
paulb@119 | 42 | |
paulb@119 | 43 | |
paulb@119 | 44 | <h1>Creating Applications: Add Selectors</h1> |
paulb@119 | 45 | |
paulb@119 | 46 | |
paulb@119 | 47 | |
paulb@119 | 48 | |
paulb@119 | 49 | <p>In the previous activity we annotated the template with |
paulb@119 | 50 | structural information, and these annotations should be sufficient in |
paulb@119 | 51 | presenting XML documents as Web pages for users to interact with. |
paulb@119 | 52 | However, in our design, we also wanted to be able to add and remove |
paulb@119 | 53 | list items from the example hierarchy:</p> |
paulb@119 | 54 | |
paulb@119 | 55 | <ul> |
paulb@119 | 56 | |
paulb@119 | 57 | <li>A list of editable items, each containing...<br /> |
paulb@119 | 58 | |
paulb@119 | 59 | |
paulb@119 | 60 | |
paulb@119 | 61 | |
paulb@119 | 62 | |
paulb@119 | 63 | |
paulb@119 | 64 | <ul> |
paulb@119 | 65 | |
paulb@119 | 66 | |
paulb@119 | 67 | |
paulb@119 | 68 | <li>A list of editable items.</li> |
paulb@119 | 69 | |
paulb@119 | 70 | |
paulb@119 | 71 | |
paulb@119 | 72 | |
paulb@119 | 73 | |
paulb@119 | 74 | |
paulb@119 | 75 | </ul> |
paulb@119 | 76 | |
paulb@119 | 77 | |
paulb@119 | 78 | |
paulb@119 | 79 | </li> |
paulb@119 | 80 | |
paulb@119 | 81 | |
paulb@119 | 82 | |
paulb@119 | 83 | </ul> |
paulb@119 | 84 | |
paulb@119 | 85 | <p>What we want to do is to have buttons beside each list item |
paulb@119 | 86 | (and subitem) which remove only that particular item. In addition, we |
paulb@119 | 87 | also want buttons which add items only to the particular list each |
paulb@119 | 88 | button appears beneath.<br /> |
paulb@119 | 89 | |
paulb@119 | 90 | |
paulb@119 | 91 | |
paulb@119 | 92 | </p> |
paulb@119 | 93 | |
paulb@119 | 94 | |
paulb@119 | 95 | |
paulb@119 | 96 | <h2>Introducing Selectors</h2> |
paulb@119 | 97 | |
paulb@119 | 98 | |
paulb@119 | 99 | |
paulb@119 | 100 | <p>Taking the HTML example from before, we add some additional annotations to the template to produce something like this:</p> |
paulb@119 | 101 | |
paulb@119 | 102 | |
paulb@119 | 103 | |
paulb@119 | 104 | <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={template:this-position()}" 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={template:this-position()}" type="submit" value="Remove" /><br /> </p><br /> <p><br /> <input name="add2={template:this-position()} type="submit" value="Add subitem" /><br /> </p><br /></div><br /><p><br /> <input name="add={template:this-position()} type="submit" value="Add item" /><br /></p><br /><br /><!-- Template text between the interesting part and the end. --><br /><br /></body><br /></html></pre> |
paulb@119 | 105 | |
paulb@119 | 106 | <h3>The Remove Buttons</h3> |
paulb@119 | 107 | <p>Some of the attributes in the original HTML code have been changed:</p> |
paulb@119 | 108 | |
paulb@119 | 109 | |
paulb@119 | 110 | |
paulb@119 | 111 | <ul> |
paulb@119 | 112 | |
paulb@119 | 113 | |
paulb@119 | 114 | |
paulb@119 | 115 | <li>The <code>input</code> element for the first <code>Remove</code> button (mapping to <code>item</code> elements in the XML document) has a modified <code>name</code> attribute, containing the special <code>remove={template:this-position()}</code> value.</li> |
paulb@119 | 116 | |
paulb@119 | 117 | <li>The <code>input</code> element for the second <code>Remove</code> button (mapping to <code>subitem</code> elements in the XML document) has a modified <code>name</code> attribute, containing the special <code>remove2={template:this-position()}</code> value.</li> |
paulb@119 | 118 | |
paulb@119 | 119 | |
paulb@119 | 120 | |
paulb@119 | 121 | |
paulb@119 | 122 | |
paulb@119 | 123 | </ul> |
paulb@119 | 124 | |
paulb@119 | 125 | |
paulb@119 | 126 | |
paulb@119 | 127 | <p>What these amendments provide is a means for the XSLForms framework |
paulb@119 | 128 | to connect together the usage of a button in the Web form with an XML |
paulb@119 | 129 | document element.</p> |
paulb@119 | 130 | |
paulb@119 | 131 | <ul> |
paulb@119 | 132 | |
paulb@119 | 133 | <li>The first <code>Remove</code> button appears within the <code>p</code> element which is annotated as mapping onto the <code>item</code> |
paulb@119 | 134 | element in the XML document. This means that the special value added |
paulb@119 | 135 | above will, in the final output, refer to that specific list item from |
paulb@119 | 136 | the XML document.</li> |
paulb@119 | 137 | |
paulb@119 | 138 | <li>The second <code>Remove</code> button appears within the <code>p</code> element which is annotated as mapping onto the <code>subitem</code> |
paulb@119 | 139 | element in the XML document. This means that the special value added |
paulb@119 | 140 | above will, in the final output, refer to that specific list (sub)item from |
paulb@119 | 141 | the XML document.</li> |
paulb@119 | 142 | |
paulb@119 | 143 | </ul> |
paulb@119 | 144 | |
paulb@119 | 145 | <h3>The Add Buttons</h3> |
paulb@119 | 146 | <p>Some additional sections have been added to the original HTML code:</p> |
paulb@119 | 147 | |
paulb@119 | 148 | <ul> |
paulb@119 | 149 | |
paulb@119 | 150 | <li>An extra paragraph appears below the <code>subitem</code> paragraph, containing an <code>input</code> element which employs the special <code>add2={template:this-position()}</code> value in the <code>name</code> attribute to represent an <code>Add subitem</code> button.</li> |
paulb@119 | 151 | |
paulb@119 | 152 | <li>An extra paragraph appears below the <code>item</code> section, containing an <code>input</code> element which employs the special <code>add={template:this-position()}</code> value in the <code>name</code> attribute to represent an <code>Add item</code> button.</li> |
paulb@119 | 153 | |
paulb@119 | 154 | </ul> |
paulb@119 | 155 | |
paulb@119 | 156 | <p>What these amendments provide is also a means for the XSLForms framework to connect these buttons to parts of the XML document.</p> |
paulb@119 | 157 | |
paulb@119 | 158 | <ul> |
paulb@119 | 159 | |
paulb@119 | 160 | <li>The <code>Add subitem</code> button appears outside the <code>p</code> element mapping onto the <code>subitem</code> element in the XML document. Instead, it appears within the <code>p</code> element mapping onto the <code>item</code> |
paulb@119 | 161 | element in the XML document. This means that the special value added |
paulb@119 | 162 | above will, in the final output, refer to a specific <code>item</code> from |
paulb@119 | 163 | the XML document, and the consequence of adding a <code>subitem</code> will be the extension of that list of <code>subitem</code> elements within that <code>item</code> element.</li> |
paulb@119 | 164 | |
paulb@119 | 165 | <li>The <code>Add item</code> button appears outside the <code>p</code> element mapping onto the <code>item</code> |
paulb@119 | 166 | element in the XML document. Instead, it appears within the <code>body</code> element mapping onto the top-level <code>structure</code> |
paulb@119 | 167 | element in the XML document. This means that the special value added |
paulb@119 | 168 | above will, in the final output, refer to the top-level <code>structure</code> |
paulb@119 | 169 | element in |
paulb@119 | 170 | the XML document, and the consequence of adding an <code>item</code> will be the extension of the main list of <code>item</code> elements.</li> |
paulb@119 | 171 | |
paulb@119 | 172 | </ul> |
paulb@119 | 173 | <div class="WebStack"> |
paulb@119 | 174 | <h3>Selector Annotation</h3> |
paulb@119 | 175 | |
paulb@119 | 176 | |
paulb@119 | 177 | |
paulb@119 | 178 | <p>Special values of the following form can be used to connect parts of |
paulb@119 | 179 | the template with elements in the XML document representation of a form:</p> |
paulb@119 | 180 | |
paulb@119 | 181 | |
paulb@119 | 182 | |
paulb@119 | 183 | <dl> |
paulb@119 | 184 | <dt><code>selector={template:this-position()}</code></dt> |
paulb@119 | 185 | |
paulb@119 | 186 | |
paulb@119 | 187 | |
paulb@119 | 188 | <dd>Given a selector name (<code>selector</code> in this example), |
paulb@119 | 189 | this special value produces a reference to an XML document element (or |
paulb@119 | 190 | attribute) in the final output. The referenced element or attribute is |
paulb@119 | 191 | defined by those <code>template:element</code> and <code>template:attribute</code> annotations on template elements which surround the template element within which this special value is used.</dd> |
paulb@119 | 192 | |
paulb@119 | 193 | |
paulb@119 | 194 | |
paulb@119 | 195 | </dl> |
paulb@119 | 196 | |
paulb@119 | 197 | |
paulb@119 | 198 | |
paulb@119 | 199 | <p>The <a href="reference.html">reference guide</a> provides a complete list of special values for use in template annotations.</p> |
paulb@119 | 200 | |
paulb@119 | 201 | |
paulb@119 | 202 | |
paulb@119 | 203 | </div> |
paulb@119 | 204 | </body> |
paulb@119 | 205 | </html> |