1.1 --- a/XSLForms/Fields.py Fri Jan 20 17:37:33 2006 +0000
1.2 +++ b/XSLForms/Fields.py Wed Jan 25 00:26:48 2006 +0000
1.3 @@ -213,18 +213,16 @@
1.4 if index < 0:
1.5 break
1.6
1.7 - # NOTE: Controversial creation of potentially non-existent
1.8 - # NOTE: nodes.
1.9 + # Where a node cannot be found, do not create a selector.
1.10
1.11 - try:
1.12 - node = self._enter_element(node, name, index)
1.13 - except FieldsError, exc:
1.14 - raise FieldsError, "In field '%s', name '%s' and index '%s' could not be added, since '%s' was found." % (
1.15 - field, name, index, exc.args[0])
1.16 + node = self._find_element(node, name, index)
1.17 + if node is None:
1.18 + break
1.19
1.20 if not selectors.has_key(selector_name):
1.21 selectors[selector_name] = []
1.22 - selectors[selector_name].append(node)
1.23 + if node is not None:
1.24 + selectors[selector_name].append(node)
1.25
1.26 def _append_element(self, node, name):
1.27
1.28 @@ -259,6 +257,23 @@
1.29
1.30 return new_node
1.31
1.32 + def _find_element(self, node, name, index):
1.33 +
1.34 + """
1.35 + From 'node' find the element with the given 'name' at the
1.36 + given 'index' position amongst the child elements. Return
1.37 + None if no such element exists.
1.38 + """
1.39 +
1.40 + elements = node.xpath("*")
1.41 + try:
1.42 + new_node = elements[index]
1.43 + if new_node.localName != name:
1.44 + return None
1.45 + except IndexError:
1.46 + return None
1.47 + return new_node
1.48 +
1.49 def _get_model_name_and_components(self, field):
1.50
1.51 """
1.52 @@ -433,6 +448,7 @@
1.53 items = [
1.54 ("_action_update", "Some value"),
1.55 ("_action_delete=/zoo$1/cage$2", "Some value"),
1.56 + ("_action_nasty=/zoo$1/cage$3", "Some value"),
1.57 ("/actions$1/update$1/selected", "Some value"), # Not actually used in output documents or input.
1.58 ("/zoo$1/name", "The Zoo זרו"),
1.59 ("/zoo$1/cage$1/name", "reptiles"),