@@ -439,19 +439,20 @@ def _apply_3to4_conversion(self, old: Element, new: Element) -> None:
439439 # Only perform the mapping if the corresponding target fields exist in the
440440 # new DD and if we don't already have a mapping for the involved paths.
441441 # use self.old_paths and self.new_paths set in _build_map
442- for p in self .old_paths :
442+ for name_path in self .old_paths :
443443 # look for name children
444- if not p .endswith ("/name" ):
444+ if not name_path .endswith ("/name" ):
445445 continue
446- parent = p .rsplit ("/" , 1 )[0 ]
447- name_path = f"{ parent } /name"
446+ parent = name_path .rsplit ("/" , 1 )[0 ]
448447 id_path = f"{ parent } /identifier"
449448 index_path = f"{ parent } /index"
450- desc_path = f"{ parent } /description"
451- new_name_path = name_path
449+ # Follow renames of parent structure
450+ new_parent = self .old_to_new .path .get (parent ) or parent
451+ desc_path = f"{ new_parent } /description"
452+ new_name_path = f"{ new_parent } /name"
452453
453- # If neither 'name' nor 'identifier' existed in the old DD, skip this parent
454- if name_path not in self . old_paths or id_path not in self .old_paths :
454+ # If 'identifier' doesn't exist in the old DD, skip this parent
455+ if id_path not in self .old_paths :
455456 continue
456457 # exclude identifier-structure (has index sibling)
457458 if index_path in self .old_paths :
@@ -462,14 +463,11 @@ def _apply_3to4_conversion(self, old: Element, new: Element) -> None:
462463 continue
463464
464465 # Map DD3 name -> DD4 description
465- if name_path not in self .old_to_new .path :
466- self ._add_rename (name_path , desc_path )
467- # GH#114: Also preserve name in DD4 name when identifier is empty
468- self .old_to_new .type_change [name_path ] = _name_identifier_3to4
469-
466+ self ._add_rename (name_path , desc_path )
467+ # GH#114: Also preserve name in DD4 name when identifier is empty
468+ self .old_to_new .type_change [name_path ] = _name_identifier_3to4
470469 # Map DD3 identifier -> DD4 name
471- if id_path in self .old_to_new .path :
472- self ._add_rename (id_path , new_name_path )
470+ self ._add_rename (id_path , new_name_path )
473471
474472 def _map_missing (self , is_new : bool , missing_paths : Set [str ]):
475473 rename_map = self .new_to_old if is_new else self .old_to_new
0 commit comments