[Erp5-report] r35527 nicolas - /erp5/trunk/utils/erp5diff/ERP5Diff.py

nobody at svn.erp5.org nobody at svn.erp5.org
Fri May 21 14:40:31 CEST 2010


Author: nicolas
Date: Fri May 21 14:40:29 2010
New Revision: 35527

URL: http://svn.erp5.org?rev=35527&view=rev
Log:
Include 'gid' in attributes allowed to build an xpath expression
with a unique identifier.

 * /erp5/object[@id='foo']/title
 * /erp5/object[@gid='2130123']/title


Modified:
    erp5/trunk/utils/erp5diff/ERP5Diff.py

Modified: erp5/trunk/utils/erp5diff/ERP5Diff.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5diff/ERP5Diff.py?rev=35527&r1=35526&r2=35527&view=diff
==============================================================================
--- erp5/trunk/utils/erp5diff/ERP5Diff.py [utf8] (original)
+++ erp5/trunk/utils/erp5diff/ERP5Diff.py [utf8] Fri May 21 14:40:29 2010
@@ -419,18 +419,24 @@
       id_val = None
       attr_map = element.attrib
       for name, value in attr_map.items():
-        if name == 'id':
+        if name in ('id', 'gid',):
           id_val = value
+          id_of_id = name
           break
 
       if id_val is not None:
-        # If an attribute 'id' is present, uses the attribute for convenience.
+        # If an attribute 'id' or 'gid' is present, uses the attribute for convenience.
         position_predicate = ''
-        len_all_similar_sibling = len(element.xpath('../*[@id = "%s"]' % id_val))
+        len_all_similar_sibling = len(element.xpath('../*[@%s = "%s"]' %\
+                                                           (id_of_id, id_val)))
         if len_all_similar_sibling > 1:
-          position = len_all_similar_sibling - element.xpath('count(following-sibling::%s[@id = "%s"])' % (element.xpath('name()'), id_val), namespaces=element.nsmap)
+          position = len_all_similar_sibling - \
+              element.xpath('count(following-sibling::%s[@%s = "%s"])' %\
+                                   (element.xpath('name()'), id_of_id, id_val),
+                                                      namespaces=element.nsmap)
           position_predicate = '[%i]' % position
-        path_list.append("%s[@id='%s']%s" % (element.xpath('name()'), id_val, position_predicate,))
+        path_list.append("%s[@%s='%s']%s" % (element.xpath('name()'), id_of_id,
+                                                  id_val, position_predicate,))
         # Increase the count, for a case where other elements with the same tag name do not have
         # 'id' attrib.
       else:




More information about the Erp5-report mailing list