Using the example of “XLSForm that looks up default values based on a selection” described Form Logic - ODK Docs, I added a second question (age) and I have no problem with the trigger/calculation populating the default when I wrap the questions in a field_list to get them on one page. However, if I place a repeat around it, then it appears that the trigger does not occur and the calculation does not populate the default. But if I remove the field_list while retaining the repeat, the trigger does seem to occur and the calculation populates the default.
I’m really confused because it works with field_list without a repeat and works with a repeat without a field_list.
2. What steps can we take to reproduce this issue?
Thanks a lot for reporting the issue and for providing all the details that helped with the investigation. It seems to be a bug in ODK Collect, or more precisely in Javarosa, the library that powers the mobile app.
I need a bit more time to fully understand what is happening under the hood and to estimate how long it might take to fix. In the meantime, in case this issue is blocking you, here is a workaround you can use:
After investigating this with the team, it turns out that the behavior you observed is not a bug in ODK Collect or JavaRosa, but rather the expected way that XPath relative references work inside predicates.
inside a predicate that queries an external instance, the call to position(../..) is evaluated relative to the external instance, not relative to your repeat group in /data. This is standard XPath behavior: in predicates, relative navigation is scoped to the node-set being filtered.
As a result, the position returned is not the position of the current repeat item, which is why the lookup fails.
Working alternatives
Both of the following expressions work because they explicitly anchor the position to the current node in the main instance:
Enketo behaves differently here because it implements parts of the XPath evaluation model slightly differently than JavaRosa. But in JavaRosa, the above behavior is correct and consistent.