Including a label answer in a following one into a loop

Hi everyone,

Description
While working on a project, our team faced a very odd bug : a calculation that we used to use in several forms for a long time all of a sudden does not work anymore.

The calculation is concatenating answer choices as values and also their labels. The concatenation purely based on values is still working, see “3 Test” (Test was entered as text for other), however the concatenation pulling in the choice labels based on the syntax jr:choice-name is not.

And here the screenshots how it manifests itself on the phone; it is not pulling in the concatenated choices correctly on the forms hosted on Kobo…

We are using EXCEL 2013 (for xls forms), KOBO Humanitarian response & ODK Collect v1.22.4. We tested also with XLS Online as a converter from xls to xml. https://opendatakit.org/xlsform/ 1

I already published it on KOBO Forum but I think ODK Forum is more appropriate.

Example :
Expected behavior : We used to have this:
image

Actual behavior: But now it appears like that:
image

What we try :

No matter what form we use, except if for V11 as hosted on Aggregate. When loading the same version number on Kobo it does not work anymore. So it is linked to the way the xml is parsed. See down below, after conversion with xls offline, the full paths are being used, this is the version that works. Converting through Kobo or through xlsform online is not retaining the full path for the jr:choice and results in failure, only the first part of the concatenation, the ID number of the net is pulled in correctly, the label of the choice made is not.

image

Extracted from xml converted through online XML converter https://opendatakit.org/xlsform/ 1

< bind calculate=“if(selected( …/NETBRAND ,‘96’),concat( …/LNTID ,’ ‘, …/BRANDOTH ),concat( …/LNTID ,’ ‘,jr:choice-name( …/NETBRAND ,’ …/NETBRAND ')))” nodeset="/GLO_FS_NET_WS_EN_FR_AR_SW_V15-XLS/Nets/NETBRAND_C" relevant=" /GLO_FS_NET_WS_EN_FR_AR_SW_V15-XLS/MOSNETS = 1" type=“string”/ >

Extracted from xml converted through Kobo and retrieved through direct download

< bind calculate=“if(selected( …/NETBRAND ,‘96’),concat( …/LNTID ,’ ‘, …/BRANDOTH ),concat( …/LNTID ,’ ‘,jr:choice-name( …/NETBRAND ,’ …/NETBRAND ')))” nodeset="/data/Nets/NETBRAND_C" relevant=" /data/MOSNETS = 1" type=“string”/ >

Converted through xls offline v1.6.0: THIS WORKS

< bind calculate=“if(selected( /GLO_FS_NET_WS_EN_FR_AR_SW_V15-XLS/Nets/NETBRAND ,‘96’),concat( /GLO_FS_NET_WS_EN_FR_AR_SW_V15-XLS/Nets/LNTID ,’ ‘, /GLO_FS_NET_WS_EN_FR_AR_SW_V15-XLS/Nets/BRANDOTH ),concat( /GLO_FS_NET_WS_EN_FR_AR_SW_V15-XLS/Nets/LNTID ,’ ‘,jr:choice-name( /GLO_FS_NET_WS_EN_FR_AR_SW_V15-XLS/Nets/NETBRAND ,’ /GLO_FS_NET_WS_EN_FR_AR_SW_V15-XLS/Nets/NETBRAND ')))” nodeset="/GLO_FS_NET_WS_EN_FR_AR_SW_V15-XLS/Nets/NETBRAND_C" relevant=" /GLO_FS_NET_WS_EN_FR_AR_SW_V15-XLS/MOSNETS = 1" type=“string”/ >

Downloading an xml from Kobo and loading it on Aggregate does not help.

Then, we also tested it through the offline tool. And we deal with the same issue as with the online one. It works with the v1.6 (https://github.com/opendatakit/xlsform-offline/releases/tag/v1.6.0) but not with the v1.10 (https://github.com/opendatakit/xlsform-offline/releases/tag/v1.10.0). When we checked the XML code we observe the same thing as with the online one. The XML obtained with v1.10 is not retaining the full path for the jr:choice and results in failure, only the first part of the concatenation, the ID number of the net is pulled in correctly, the label of the choice made is not.

Here are the two version :
V 1.10 :
< bind calculate="if(selected( ../NETBRAND ,'96'),concat( ../LNTID ,' ', ../BRANDOTH ),concat( ../LNTID ,' ',jr:choice-name( ../NETBRAND ,' ../NETBRAND ')))" nodeset="/IssueSENS/Nets/NETBRAND_C" relevant=" /IssueSENS/MOSNETS = 1" type="string"/>

V 1.6
< bind calculate="if(selected( /IssueSENS/Nets/NETBRAND ,'96'),concat( /IssueSENS/Nets/LNTID ,' ', /IssueSENS/Nets/BRANDOTH ),concat( /IssueSENS/Nets/LNTID ,' ',jr:choice-name( /IssueSENS/Nets/NETBRAND ,' /IssueSENS/Nets/NETBRAND ')))" nodeset="/IssueSENS/Nets/NETBRAND_C" relevant=" /IssueSENS/MOSNETS = 1" type="string"/>

It only works correctly when converting the xls through the offline tool https://github.com/opendatakit/xlsform-offline/releases/tag/v1.10.0 1 (note: the online xls form converter also does not work!) and loading it on Aggregate.

Steps to Reproduce

  1. Upload the following XLSForm in KOBO
    IssueSENS.xls (81 KB)
  2. Fill it
  3. Observe this issue with the question “select the brand of the net under which the household member slept” (row 61)

Might be the changes that KOBO did in the code that corrected the other bugs recently ?

If anyone have an idea will be happy to hear about it :slight_smile:

Thank you,
Chloé

1 Like

Hi @ChloeLaborde

your calculation requires indexed-repeat() function. It should be like:
if(selected(${NETBRAND},'96'),concat(${LNTID},' ',${BRANDOTH}),concat(${LNTID},' ',jr:choice-name(indexed-repeat(${NETBRAND},${Nets},${LNTID}),’${NETBRAND}’)))

instead of
if(selected(${NETBRAND},'96'),concat(${LNTID},' ',${BRANDOTH}),concat(${LNTID},' ',jr:choice-name(${NETBRAND},'${NETBRAND}')))

I'm not an expert in this area so maybe someone more experienced can explain if it's needed or if it's a bug @LN @Xiphware

Thanks for all the careful troubleshooting you've already done, @ChloeLaborde.

It's possible that using indexed-repeat as @Grzesiek2010 suggested will get around the issue but it shouldn't be necessary. The fundamental problem seems to be something about jr:choice-name's interaction with relative paths that go up one step. That is, ../NETBRAND should refer to the same thing as /IssueSENS/Nets/NETBRAND but it doesn't.

It looks like @Xiphware actually reported this already at https://github.com/opendatakit/javarosa/issues/435 but no one has addressed it yet. I'll try to take it on soon.

In the mean time, please use the older XLSForm conversion tool.

1 Like