Skip to content

Commit

Permalink
add: support for instance expression conversion where reference not used
Browse files Browse the repository at this point in the history
- if an instance expression appears in a label, in order for it to be
  evaluated and replaced it needs to be converted to an output node.
  The trigger for that was only a pyxform reference, but it's possible
  that users may want an expression that doesn't use a reference.
  • Loading branch information
lindsay-stevens committed Aug 3, 2023
1 parent d8a3fc0 commit ca010a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pyxform/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,11 +1073,14 @@ def _var_repl_output_function(matchobj):
# need to make sure we have reason to replace
# since at this point < is &lt,
# the net effect &lt gets translated again to &amp;lt;
if "{" in original_xml:
pass_1 = instance_expression.replace_with_output(original_xml, context, self)
pass_2 = re.sub(BRACKETED_TAG_REGEX, _var_repl_output_function, pass_1)
return pass_2, not pass_2 == original_xml
return text, False
xml_text = instance_expression.replace_with_output(original_xml, context, self)
if "{" in xml_text:
xml_text = re.sub(BRACKETED_TAG_REGEX, _var_repl_output_function, xml_text)
changed = xml_text != original_xml
if changed:
return xml_text, True
else:
return text, False

# pylint: disable=too-many-arguments
def print_xform_to_file(
Expand Down
6 changes: 6 additions & 0 deletions tests/test_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ def test_instance_expression__permutations(self):
"instance('c2')/root/item[contains(name, instance('c1')/root/item[name = /test_name/q1 ]/label)]/label"
},
),
# Instance expression with predicate not using a pyxform token.
Case(
"instance('c1')/root/item[name = 'y']/label",
xpq.body_input_label_output_value("note"),
{"instance('c1')/root/item[name = 'y']/label"},
),
]
wrap_scenarios = ("{}", "Text {}", "{} text", "Text {} text")
# All cases together in one.
Expand Down

0 comments on commit ca010a1

Please sign in to comment.