1.1 --- a/XSLForms/Fields.py Thu Dec 23 15:07:53 2004 +0000
1.2 +++ b/XSLForms/Fields.py Sun Dec 26 18:47:08 2004 +0000
1.3 @@ -1,11 +1,6 @@
1.4 #!/usr/bin/env python
1.5
1.6 """
1.7 -NOTE: Add support for multiple values from fields, perhaps using
1.8 -NOTE: the following notation:
1.9 -NOTE:
1.10 -NOTE: /package#1/categories#1/category#n/value
1.11 -
1.12 Classes which process field collections, producing instance
1.13 documents. Each field entry consists of a field name mapped
1.14 to a string value, where the field name may have the following
1.15 @@ -25,6 +20,11 @@
1.16 /zoo#1/cage#2/name
1.17 /zoo#1/funding#3/contributor#1/name
1.18
1.19 +Where multiple values can be collected for a given field, the
1.20 +following notation is employed:
1.21 +
1.22 + /package#1/categories#1/category##value
1.23 +
1.24 Some fields may contain the "=" string. This string is
1.25 reserved and all text following it is meant to specify a path
1.26 into a particular document. For example:
1.27 @@ -106,14 +106,35 @@
1.28
1.29 elif len(t) == 2:
1.30
1.31 - # Convert from one-based indexing (the position() function)
1.32 - # to zero-based indexing.
1.33 + # Convert from one-based indexing (the position()
1.34 + # function) to zero-based indexing.
1.35
1.36 name, index = t[0], int(t[1]) - 1
1.37 if index < 0:
1.38 break
1.39 node = self._enter_element(node, name, index)
1.40
1.41 + elif len(t) == 3 and t[1] == "":
1.42 +
1.43 + # Multivalued fields.
1.44 +
1.45 + if not self.values_are_lists:
1.46 + values = [value]
1.47 + else:
1.48 + values = value
1.49 +
1.50 + name = t[0]
1.51 + for index in range(0, len(values)):
1.52 + subnode = self._enter_element(node, name, index)
1.53 + subvalue = values[index]
1.54 +
1.55 + # Convert the value to Unicode if necessary.
1.56 +
1.57 + if type(subvalue) == type(""):
1.58 + subvalue = unicode(subvalue, encoding=self.encoding)
1.59 +
1.60 + subnode.setAttributeNS(EMPTY_NAMESPACE, t[2], subvalue)
1.61 +
1.62 def complete_selectors(self, selectors, fields, documents):
1.63
1.64 """
1.65 @@ -307,7 +328,8 @@
1.66 ("/zoo#1/cage#2/animal#2/property#2/value", "high"),
1.67 ("/zoo#1/funding#3/type", "private"),
1.68 ("/zoo#1/funding#3/contributor#1/name", "Animal Corporation"),
1.69 - ("/zoo#1/funding#3/contributor#1/amount", "543210.987")
1.70 + ("/zoo#1/funding#3/contributor#1/amount", "543210.987"),
1.71 + ("/zoo#1/funding#3/contributor#1/industry##type", "animals")
1.72 ]
1.73
1.74 import time