@@ -370,34 +370,45 @@ def _handle_value(self, value, log_id):
370
370
@classmethod
371
371
def _replace_same_name_entities (cls , tree ):
372
372
"""
373
- Changes same section names in the doc by adding <-{index}> to the next section occurrences.
373
+ Changes same section names in the doc by adding <-{index}>
374
+ to the next section occurrences.
374
375
:param tree: ElementTree of the doc
375
376
:return: ElementTree
376
377
"""
377
378
sec_map = {}
378
379
prop_map = {}
379
380
root = tree .getroot ()
380
381
for sec in root .iter ("section" ):
381
- n = sec .find ("name" )
382
- if n is not None :
383
- cls ._change_entity_name (sec_map , n )
382
+
383
+ sec_name = sec .find ("name" )
384
+ if sec_name is not None :
385
+ cls ._change_entity_name (tree , sec_map , sec_name )
384
386
else :
385
387
raise Exception ("Section attribute name is not specified" )
388
+
386
389
for prop in sec .iter ("property" ):
387
390
if prop .getparent () == sec :
388
- n = prop .find ("name" )
389
- if n is not None :
390
- cls ._change_entity_name (prop_map , n )
391
+ prop_name = prop .find ("name" )
392
+ if prop_name is not None :
393
+ cls ._change_entity_name (tree , prop_map , prop_name )
391
394
prop_map .clear ()
392
395
return tree
393
396
394
397
@staticmethod
395
- def _change_entity_name (elem_map , name ):
396
- if name .text not in elem_map :
397
- elem_map [name .text ] = 1
398
+ def _change_entity_name (tree , elem_map , name ):
399
+ """
400
+ Adds numbering to identical element names where their odml.Section
401
+ or odml.Property parents reside on the same level in the tree.
402
+ :param tree: The element tree containing the 'name' element.
403
+ :param elem_map: lxml path to occurrence maps of named Sections or Properties.
404
+ :param name: lxml element containing the name text of a Section or Property.
405
+ """
406
+ named_path = "%s:%s" % (tree .getpath (name .getparent ().getparent ()), name .text )
407
+ if named_path not in elem_map :
408
+ elem_map [named_path ] = 1
398
409
else :
399
- elem_map [name . text ] += 1
400
- name .text += "-" + str (elem_map [name . text ])
410
+ elem_map [named_path ] += 1
411
+ name .text += "-" + str (elem_map [named_path ])
401
412
402
413
def _log (self , msg ):
403
414
"""
0 commit comments