@@ -77,28 +77,33 @@ def register_nsmap():
7777register_nsmap ()
7878
7979
80- def share_same_repeat_parent (
80+ def get_path_relative_to_lcar (
8181 target : SurveyElement ,
8282 source : SurveyElement ,
8383 lcar_steps_source : int ,
8484 lcar : SurveyElement ,
8585 reference_parent : bool = False ,
86- ):
86+ ) -> tuple [ int , str ] :
8787 """
88- Returns a tuple of the number of steps from the source xpath to the lowest common
89- ancestor repeat, and the xpath to the target xpath from the LCAR.
88+ Get the number of steps from the source to the LCAR, and the path to the target.
9089
91- Function only called if target and source share a ancestor repeat .
90+ Implementation assumes that it is only called if target and source have an LCAR .
9291
93- For example,
94- xpath = /data/repeat_a/group_a/name
95- context_xpath = /data/repeat_a/group_b/age
92+ Example:
93+ target = /data/repeat_a/group_a/name
94+ source = /data/repeat_a/group_b/age
95+ return = (2, "/group_a/name")
9696
97- returns (2, '/group_a/name')'
97+ :param target: The reference target, like "/data/repeat/q1" for "${q1}"
98+ :param source: The reference source, where the reference is located.
99+ :param lcar_steps_source: The number of path segments from the source to the LCAR.
100+ :param lcar: The lowest common ancestor repeat.
101+ :param reference_parent: If True, calculate to the LCAR parent rather than the LCAR.
102+ This may not be actually honoured depending on the topography.
98103 """
99104
100- def is_repeat (i : SurveyElement ) -> bool :
101- return isinstance (i , Section ) and i .type == constants .REPEAT
105+ def is_repeat (e : SurveyElement ) -> bool :
106+ return isinstance (e , Section ) and e .type == constants .REPEAT
102107
103108 # Currently reference_parent only used for itemsets containing a pyxform variable,
104109 # i.e. `select_one ${ref}`. In that case, an extra step up the reference path may be
@@ -1092,7 +1097,7 @@ def _relative_path(ref_name: str, _use_current: bool) -> str | None:
10921097 other = target , group_type = constants .REPEAT
10931098 )
10941099 if relation [0 ] == "Common Ancestor" :
1095- steps , ref_path = share_same_repeat_parent (
1100+ steps , ref_path = get_path_relative_to_lcar (
10961101 target = target ,
10971102 source = context ,
10981103 lcar_steps_source = relation [1 ],
0 commit comments