1.1 --- a/XSLForms/Utils.py Sun Mar 12 15:17:57 2006 +0000
1.2 +++ b/XSLForms/Utils.py Sun Mar 12 15:18:15 2006 +0000
1.3 @@ -20,29 +20,31 @@
1.4 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
1.5 """
1.6
1.7 -def add_elements(positions, element_name, element_parent_name=None):
1.8 +def add_elements(positions, *element_names):
1.9
1.10 """
1.11 - At the specified 'positions' in a document, add a new element of the given
1.12 - 'element_name'. If the optional 'element_parent_name' is specified, ensure
1.13 - the presence of special parent elements bearing that name, adding them at
1.14 - the specified 'positions' where necessary, before adding the elements with
1.15 - the stated 'element_name' beneath such parent elements.
1.16 + At the specified 'positions' in a document, add a new element using the
1.17 + first of the given 'element_names' inside any subsequent element named in
1.18 + the 'element_names' list, in turn creating new parent elements for each
1.19 + element name found.
1.20 """
1.21
1.22 if not positions:
1.23 return
1.24 + reversed_element_names = list(element_names)[:]
1.25 + reversed_element_names.reverse()
1.26 for position in positions:
1.27 - if element_parent_name:
1.28 - parent_elements = position.xpath(element_parent_name)
1.29 - if not parent_elements:
1.30 - parent_element = position.ownerDocument.createElementNS(None, element_parent_name)
1.31 - position.appendChild(parent_element)
1.32 + element = position
1.33 + for element_name in reversed_element_names[:-1]:
1.34 + found_elements = element.xpath(element_name)
1.35 + if not found_elements:
1.36 + new_element = element.ownerDocument.createElementNS(None, element_name)
1.37 + element.appendChild(new_element)
1.38 else:
1.39 - parent_element = parent_elements[0]
1.40 - else:
1.41 - parent_element = position
1.42 - parent_element.appendChild(position.ownerDocument.createElementNS(None, element_name))
1.43 + new_element = found_elements[0]
1.44 + element = new_element
1.45 + new_element = element.ownerDocument.createElementNS(None, reversed_element_names[-1])
1.46 + element.appendChild(new_element)
1.47
1.48 def remove_elements(positions):
1.49