Closed jkpr closed 2 years ago
pyxform v1.3.3 (and tip of repo as of Dec 29, 2020), Python v3.8
We noticed that pulldata was not being parsed correctly. See attached HQ-bfp2-v102.xlsx. The calculate statement is
pulldata
HQ-bfp2-v102.xlsx
if(${calc_p1_member_here_yes}, pulldata('hq_data', 'num_HH_members', 'metainstanceID', ${p1_hh}), (count-selected(${p1_fq_id})))
Notice the newline (\n) right before pulldata.
\n
This led to the following in the output XML:
<instance id="if(${calc_p1_member_here_yes}" src="jr://file-csv/if(${calc_p1_member_here_yes}.csv"/>
The bind was correct:
<bind calculate="if( /HHQ/calc_p1_member_here_yes , pulldata('hq_data', 'num_HH_members', 'metainstanceID', /HHQ/p1_hh ), (count-selected( /HHQ/p1_fq_id )))" nodeset="/HHQ/hq_total_mem" type="string"/>
Convert the attached form HQ-bfp2-v102.xlsx.
The XML should have
<instance id="hq_data" src="jr://file-csv/hq_data.csv"/>
since the calculate statement is not malformed.
calculate
The problem is in the Regular Expression that parses the calculate statement
https://github.com/XLSForm/pyxform/blob/v1.3.3/pyxform/survey.py#L379
pulldata_arguments = re.sub(".*pulldata\s*\(\s*", "", pulldata_call)
The regex match does not span across newlines, i.e. \n.
If we change our calculate statement to put everything on one line (see HQ-bfp2-v103.xlsx)
then we get what we want, i.e. <instance id="hq_data" src="jr://file-csv/hq_data.csv"/>
HQ-bfp2-v102.xlsx HQ-bfp2-v103.xlsx
Software and hardware versions
pyxform v1.3.3 (and tip of repo as of Dec 29, 2020), Python v3.8
Problem description
We noticed that
pulldata
was not being parsed correctly. See attachedHQ-bfp2-v102.xlsx
. The calculate statement isNotice the newline (
\n
) right beforepulldata
.This led to the following in the output XML:
The bind was correct:
Steps to reproduce the problem
Convert the attached form
HQ-bfp2-v102.xlsx
.Expected behavior
The XML should have
since the
calculate
statement is not malformed.Other information
The problem is in the Regular Expression that parses the calculate statement
https://github.com/XLSForm/pyxform/blob/v1.3.3/pyxform/survey.py#L379
The regex match does not span across newlines, i.e.
\n
.If we change our calculate statement to put everything on one line (see HQ-bfp2-v103.xlsx)
then we get what we want, i.e.
<instance id="hq_data" src="jr://file-csv/hq_data.csv"/>
HQ-bfp2-v102.xlsx HQ-bfp2-v103.xlsx