XSLTools

docs/advice.html

211:a4006b6da1a0
2005-08-25 paulb [project @ 2005-08-25 14:43:34 by paulb] Changed the path encoding to UTF-8 - if this is not correct, ISO-8859-1 will be tried anyway.
     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">     3 <head>     4   <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type" />     5   <title>Creating Applications: Recommendations and Advice</title>     6   <meta name="generator"     7  content="amaya 8.1a, see http://www.w3.org/Amaya/" />     8   <link href="styles.css" rel="stylesheet" type="text/css" />     9 </head>    10 <body>    11 <h1>Creating Applications: Recommendations and Advice</h1>    12 <ol>    13 </ol>    14 <p>To avoid hard-to-explain problems when designing and testing    15 templates, the following advice may be of some use:</p>    16 <h2>Beware of Nesting Elements in Multiple-Choice Elements</h2>    17 <p>It is not necessarily a good idea to nest elements inside    18 multiple-choice elements like this:</p>    19 <pre>&lt;multi&gt;<br />  &lt;multi-enum value="1"/&gt;<br />  &lt;multi-enum value="1"/&gt;<br />  &lt;multi-enum value="1"/&gt;<br />  &lt;nested value="x"/&gt;<br />&lt;/multi&gt;</pre>    20 <p>The reason for this is that the number of multiple-choice values may    21 vary within your application, and&nbsp;the nested elements will appear    22 at a different position depending on how many such values have been    23 inserted. Whilst this might not affect some applications, at least not    24 to begin with, the usage of more advanced features (<a    25  href="in-page-updates.html">in-page updates</a>, for example) will    26 probably expose    27 problems due to the way XSLForms reconstructs the XML document data    28 from the input form data.</p>    29 <h2>Beware of Adding Elements into Mixtures of Elements</h2>    30 <p>Although we ignore this rule with the example in this documentation,    31 it is necessary to be aware of problems with adding and removing    32 elements where other elements may reside. Consider part of our form    33 data structure:</p>    34 <pre>&lt;item value="a"&gt;<br />  &lt;type&gt;<br />    &lt;type-enum value="1"/&gt;<br />  &lt;/type&gt;<br />  &lt;subitem value="x"/&gt;<br />&lt;/item&gt;</pre>    35 <p>Provided that we control the process of adding and removing the    36 elements, making sure that they always reside at the end of the element    37 collection inside the&nbsp;<code>item</code> element, and that they    38 always follow a known number of elements, we can avoid issues with more    39 advanced features (<a href="in-page-updates.html">in-page updates</a>,    40 for example), although using such features on the&nbsp;<code>subitem</code>    41 elements themselves may cause problems that may only be resolved by    42 moving the&nbsp;<code>subitem</code> elements into a container element    43 of their own:</p>    44 <pre>&lt;item value="a"&gt;<br />  &lt;type&gt;<br />    &lt;type-enum value="1"/&gt;<br />  &lt;/type&gt;<br />  &lt;subitems&gt;<br />    &lt;subitem value="x"/&gt;<br />  &lt;/subitems&gt;<br />&lt;/item&gt;</pre>    45 <h2>Make Sure the Output Structure Agrees with the Template</h2>    46 <ol>    47 </ol>    48 <p>Since XSLForms templates essentially describe the presentation of an    49 XML document, it is vital that the output form data structure agrees    50 with the template - that is, the output structure can be properly    51 processed by the template and that all parts of the template are    52 displayed as expected. It is also very important to make sure that    53 transformations on the input document produce all    54 the necessary elements for the output document so that the resulting    55 page gives the user the opportunity to specify data that is missing.    56 Consider this section of an example template:</p>    57 <pre>&lt;p template:element="package"&gt;<br />  &lt;p template:element="author"&gt;<br />    Name: &lt;input template:attribute="name" name="{template:this-attribute()}" type="text" value="{$this-value}"/&gt;<br />  &lt;/p&gt;<br />&lt;/p&gt;</pre>    58 <p>Here, if the&nbsp;<code>author</code> element is not found in the    59 output structure, no field will be produced in the Web page, no    60 opportunity will be given for an author to be specified, and no author    61 information will subsequently be editable. One solution is to introduce    62 the&nbsp;<code>author</code> element into the XML document when    63 creating the&nbsp;<code>package</code> element - this should then    64 "bootstrap" the process and ensure that the author details will remain    65 editable as long as the&nbsp;<code>package</code> element exists.</p>    66 <ol>    67 </ol>    68 </body>    69 </html>