Commit c9ecea0b authored by Nicolas Delaby's avatar Nicolas Delaby

Fix relative calculation of position for xupdate:insert-before nodes

parent 87e4471c
......@@ -235,7 +235,7 @@ class ERP5Diff:
append_element = last_append_element
elif relative_next is not None and relative_next not in element_list:
append_element = etree.SubElement(root, '{%s}insert-before' % self._ns, nsmap=element.nsmap)
path_list = self._makeRelativePathList([relative_next])
path_list = self._makeRelativePathList([relative_next], before=1)
next_sibling_path = self._concatPath(path, path_list[0])
append_element.attrib['select'] = next_sibling_path
elif relative_previous is not None and relative_previous not in element_list:
......@@ -400,7 +400,7 @@ class ERP5Diff:
return True
return False
def _makeRelativePathList(self, element_list):
def _makeRelativePathList(self, element_list, before=0):
"""
Make a list of relative paths from a list of elements.
"""
......@@ -429,7 +429,7 @@ class ERP5Diff:
len_all_similar_sibling = len(element.findall('../%s' % element.tag))
if len_all_similar_sibling > 1:
position = len_all_similar_sibling - len(list(element.itersiblings(tag=element.tag)))
path_list.append('%s[%d]' % (element.xpath('name()'), position))
path_list.append('%s[%d]' % (element.xpath('name()'), position-before))
else:
path_list.append(element.xpath('name()'))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment