Commit 5fe752bc authored by Nicolas Delaby's avatar Nicolas Delaby

Append position in xpath expression when value of id attribute is not unique

parent 3bcf915d
...@@ -238,10 +238,8 @@ class ERP5Diff: ...@@ -238,10 +238,8 @@ class ERP5Diff:
id_list = [] id_list = []
for attr_map in (element1.attrib, element2.attrib): for attr_map in (element1.attrib, element2.attrib):
for name, value in attr_map.items(): if 'id' in attr_map:
if name == 'id': id_list.append(attr_map['id'])
id_list.append(value)
break
if len(id_list) == 0: if len(id_list) == 0:
return True return True
...@@ -283,7 +281,7 @@ class ERP5Diff: ...@@ -283,7 +281,7 @@ class ERP5Diff:
def _checkEmptiness(self, element): def _checkEmptiness(self, element):
""" """
Check if an element has child values. Check if an element has Element or Text nodes
""" """
for child in element: for child in element:
if type(child) == etree._Element: if type(child) == etree._Element:
...@@ -327,7 +325,12 @@ class ERP5Diff: ...@@ -327,7 +325,12 @@ class ERP5Diff:
if id_val is not None: if id_val is not None:
# If an attribute 'id' is present, uses the attribute for convenience. # If an attribute 'id' is present, uses the attribute for convenience.
path_list.append("%s[@id='%s']" % (element.tag, id_val)) position_predicate = ''
len_all_similar_sibling = len(element.xpath('../*[@id = "%s"]' % id_val))
if len_all_similar_sibling > 1:
position = len_all_similar_sibling - element.xpath('count(following-sibling::%s[@id = "%s"])' % (element.tag, id_val) )
position_predicate = '[%i]' % position
path_list.append("%s[@id='%s']%s" % (element.tag, id_val, position_predicate,))
# Increase the count, for a case where other elements with the same tag name do not have # Increase the count, for a case where other elements with the same tag name do not have
# 'id' attrib. # 'id' attrib.
count_map[element.tag] += 1 count_map[element.tag] += 1
......
...@@ -145,7 +145,7 @@ ERP5Diff Usage and its output example ...@@ -145,7 +145,7 @@ ERP5Diff Usage and its output example
<xupdate:update select="/object[@id='313730']/description">description1 --- $sdfrç_sdfsçdf_oisfsopf</xupdate:update> <xupdate:update select="/object[@id='313730']/description">description1 --- $sdfrç_sdfsçdf_oisfsopf</xupdate:update>
<xupdate:update select="/object[@id='313730']/language/attribute::type">None</xupdate:update> <xupdate:update select="/object[@id='313730']/language/attribute::type">None</xupdate:update>
<xupdate:update select="/object[@id='313730']/language"/> <xupdate:update select="/object[@id='313730']/language"/>
<xupdate:remove select="/object[@id='313730']/workflow_action[@id='edit_workflow']"/> <xupdate:remove select="/object[@id='313730']/workflow_action[@id='edit_workflow'][2]"/>
</xupdate:modifications> </xupdate:modifications>
5. update two elements includes some symbols 5. update two elements includes some symbols
...@@ -208,8 +208,8 @@ ERP5Diff Usage and its output example ...@@ -208,8 +208,8 @@ ERP5Diff Usage and its output example
>>> erp5diff.compare(old_xml, new_xml) >>> erp5diff.compare(old_xml, new_xml)
>>> erp5diff.output() >>> erp5diff.output()
<xupdate:modifications xmlns:xupdate="http://www.xmldb.org/xupdate" version="1.0"> <xupdate:modifications xmlns:xupdate="http://www.xmldb.org/xupdate" version="1.0">
<xupdate:update select="/object[@id='313730']/workflow_action[@id='edit_workflow']/time">2009/08/28 19:12:40.905 GMT+9</xupdate:update> <xupdate:update select="/object[@id='313730']/workflow_action[@id='edit_workflow'][2]/time">2009/08/28 19:12:40.905 GMT+9</xupdate:update>
<xupdate:update select="/object[@id='313730']/workflow_action[@id='edit_workflow']/time">2009/08/28 19:12:40.910 GMT+9</xupdate:update> <xupdate:update select="/object[@id='313730']/workflow_action[@id='edit_workflow'][3]/time">2009/08/28 19:12:40.910 GMT+9</xupdate:update>
</xupdate:modifications> </xupdate:modifications>
7. insert and remove elements 7. insert and remove elements
...@@ -637,9 +637,9 @@ does not work as bellow example. This is a known bug. ...@@ -637,9 +637,9 @@ does not work as bellow example. This is a known bug.
>>> erp5diff.compare(old_xml, new_xml) >>> erp5diff.compare(old_xml, new_xml)
>>> erp5diff.output() >>> erp5diff.output()
<xupdate:modifications xmlns:xupdate="http://www.xmldb.org/xupdate" version="1.0"> <xupdate:modifications xmlns:xupdate="http://www.xmldb.org/xupdate" version="1.0">
<xupdate:update select="/object[@id='313730']/workflow_action[2]/time">2009/08/29 19:12:34.432 GMT+9</xupdate:update> <xupdate:update select="/object[@id='313730']/workflow_action[@id='edit_workflow'][2]/time">2009/08/29 19:12:34.432 GMT+9</xupdate:update>
<xupdate:update select="/object[@id='313730']/workflow_action[3]/time">2009/08/30 19:12:34.434 GMT+9</xupdate:update> <xupdate:update select="/object[@id='313730']/workflow_action[@id='edit_workflow'][3]/time">2009/08/30 19:12:34.434 GMT+9</xupdate:update>
<xupdate:update select="/object[@id='313730']/workflow_action[4]/time">2009/08/31 19:12:34.436 GMT+9</xupdate:update> <xupdate:update select="/object[@id='313730']/workflow_action[@id='edit_workflow'][4]/time">2009/08/31 19:12:34.436 GMT+9</xupdate:update>
</xupdate:modifications> </xupdate:modifications>
22. Modify attributes of sequencial objects 22. Modify attributes of sequencial objects
......
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