# HG changeset patch # User paulb # Date 1121779915 0 # Node ID 5080928bac8e43991fdf72bc255d28a10a589eab # Parent 370ce9bb485a1c0a816ea4146f41e18d043cd5dc [project @ 2005-07-19 13:31:55 by paulb] Improved the selectors document. diff -r 370ce9bb485a -r 5080928bac8e docs/selectors.html --- a/docs/selectors.html Tue Jul 19 12:31:03 2005 +0000 +++ b/docs/selectors.html Tue Jul 19 13:31:55 2005 +0000 @@ -1,202 +1,104 @@
-In the previous activity we annotated the template with structural information, and these annotations should be sufficient in presenting XML documents as Web pages for users to interact with. However, in our design, we also wanted to be able to add and remove -list items from the example hierarchy:
- -What we want to do is to have buttons beside each
-list item
-(and subitem) which remove only that particular item. In addition, we
-also want buttons which add items only to the particular list each
-button appears beneath.
-
-
So, we need to add buttons to the Web form which, -upon being pressed, provide information about their context to -the XSLForms framework and subsequently to the application, so that we -know which part of the form is to be altered. To make sure that such -contextual information is available in the Web form, we must include -such references in the descriptions of these buttons in the template.
- -The concept of a "selector" is a reference which is expressed -in a special notation in the template, converted to concrete references -in the final output, and can be interpreted when a user submits a form -such that the associated section of the XML document version of the -form data can be identified in connection with an action. In other -words, we write a special value into the definition of a button in a -Web form which can automatically be used to refer to other form data -when the form is submitted.
- -Taking the HTML example from before, we add some -additional annotations to the template to produce something +
The buttons in the template are implicitly associated with +specific items and subitems, and when such buttons are pressed - for +example, to remove an item from the list - our application will want to +know on which item the removal action is to take place. In order to +connect the buttons with specific parts of the form data structure, a +special notation is used, and such notation turns elements such as +buttons into "selectors" - things which select parts of the structure +so that an operation can be carried out on those parts.
+Taking the example HTML code from before, we add some of these +selector annotations to the template to produce something like this:
- -<html xmlns="http://www.w3.org/1999/xhtml"- +
xmlns:template="http://www.boddie.org.uk/ns/xmltools/template">
<head>
<title>Example</title>
</head>
<body template:element="structure">
<form action="" method="POST">
<!-- Template text between the start and the interesting part. -->
<div template:element="item">
<p>
<span template:attribute="value">
Some item: <input name="{template:field-name()}" type="text" value="{$this-value}" />
</span>
<input name="remove={template:this-position()}" type="submit" value="Remove" />
</p>
<p>
Itself containing more items:
</p>
<p template:element="subitem">
<span template:attribute="subvalue">
Sub-item: <input name="{template:field-name()}" type="text" value="{$this-value}" />
</span>
<input name="remove2={template:this-position()}" type="submit" value="Remove" />
</p>
<p>
<input name="add2={template:this-position()}" type="submit" value="Add subitem" />
</p>
</div>
<p>
<input name="add={template:this-position()}" type="submit" value="Add item" />
</p>
<!-- Template text between the interesting part and the end. -->
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:template="http://www.boddie.org.uk/ns/xmltools/template">
<head>
<title>Example</title>
</head>
<body template:element="structure">
<form action="" method="POST">
<!-- Template text between the start and the interesting part. -->
<div template:element="item">
<p>
Some item: <input template:attribute="value" name="{template:field-name()}" type="text" value="{$this-value}" />
<input name="remove={template:this-position()}" type="submit" value="Remove" />
</p>
<p>
Itself containing more items:
</p>
<p template:element="subitem">
Sub-item: <input template:attribute="subvalue" name="{template:field-name()}" type="text" value="{$this-value}" />
<input name="remove2={template:this-position()}" type="submit" value="Remove" />
</p>
<p>
<input name="add2={template:this-position()}" type="submit" value="Add subitem" />
</p>
</div>
<p>
<input name="add={template:this-position()}" type="submit" value="Add item" />
</p>
<!-- Template text between the interesting part and the end. -->
</form>
</body>
</html>
Some of the attributes in the original HTML code have been +
Some of the attributes in the previous HTML code have been changed:
-input
element for the
-first Remove
button (mapping
-to item
elements in the XML document)
-has a modified name
attribute,
-containing the special remove={template:this-position()}
-value.Remove
button has a modified name
+attribute,
+containing a special value.
input
element for the second Remove
-button (mapping to subitem
elements in the
-XML document) has a modified name
-attribute, containing the special remove2={template:this-position()}
-value.name
+attribute, containing a special value.
What these amendments provide is a means for the XSLForms framework -to connect together the usage of a button in the Web form with an XML -document element.
- +to connect together these buttons with a specific element in the +form data.Remove
button
-appears within the p
element which is
-annotated as mapping onto the item
-element in the XML document. This means that the special value added
-above will, in the final output, refer to that specific list item from
-the XML document.div
element which maps onto items
+in the form data. This means that each button will refer to a
+specific item in the form being edited.
Remove
button appears
-within the p
element which is
-annotated as mapping onto the subitem
-element in the XML document. This means that the special value added
-above will, in the final output, refer to that specific list (sub)item
-from
-the XML document.p
element which maps onto subitems in the
+form data. This means that each button will refer to a
+specific subitem in the form being edited.
Some additional sections have been added to the original HTML +
Some other attributes have been changed in the previous HTML code:
-subitem
-paragraph, containing an input
-element which employs the special add2={template:this-position()}
-value in the name
attribute to
-represent an Add subitem
button.item
-section, containing an input
element
-which employs the special add={template:this-position()}
-value in the name
attribute to
-represent an Add item
button.input
element for the
+first Add
button has a modified name
+attribute,
+containing a special value.input
element for the second Add
+button has a modified name
+attribute, containing a special value.What these amendments provide is also a means for the XSLForms -framework to connect these buttons to parts of the XML document.
- +framework to connect these buttons to specific parts of the form data.Add subitem
button appears
-outside the p
element mapping onto
-the subitem
element in the XML
-document. Instead, it appears within the p
-element mapping onto the item
-element in the XML document. This means that the special value added
-above will, in the final output, refer to a specific item
-from
-the XML document, and the consequence of adding a subitem
-will be the extension of that list of subitem
-elements within that item
element.p
element which maps onto subitems in the
+form data. Instead, it appears within the p
+element which maps onto items. This means that each button will refer
+to a specific item in the form being edited, and the consequence of
+adding a subitem will be the extension of that item's list of subitems.
Add item
button
appears outside the p
-element mapping onto the item
-element in the XML document. Instead, it appears within the body
-element mapping onto the top-level structure
-element in the XML document. This means that the special value added
-above will, in the final output, refer to the top-level structure
+element which maps onto items in the form data. Instead, it appears
+within the body
+element which maps onto the top-level structure
+element in the form data. This means that each button will refer to the
+top-level structure
element in
-the XML document, and the consequence of adding an item
will
-be the extension of the main list of item
-elements.Special values of the following form can be used to connect -parts of the template with elements in the XML document representation -of a form:
- -selector={template:this-position()}
selector
in
-this example), this special value produces a reference to an XML
-document element (or attribute) in the final output. The referenced
-element or attribute is defined by those template:element
-and template:attribute
annotations on
-template elements which surround the template element within
-which this special value is used.The reference guide -provides a complete list of special values for use in template -annotations.
- -Whilst many forms consist only of text fields and action buttons, other types of data are very likely to also be used. Multiple-choice or enumerated value fields in forms are covered in the next activity in the development process.
- +Whilst many forms consist only of text fields and action buttons, +other types of data are very likely to also be used. Multiple-choice or enumerated value fields in +forms are covered in the next activity in the development process.