Commit 6aa55931 authored by Nicolas Delaby's avatar Nicolas Delaby

Include 'gid' in attributes allowed to build an xpath expression

with a unique identifier.

 * /erp5/object[@id='foo']/title
 * /erp5/object[@gid='2130123']/title
parent 6d753a49
......@@ -419,18 +419,24 @@ class ERP5Diff:
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:
......
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