Concatenate references to create new reference ${var${randnum}}

Dear all,

I am trying to create a variable which refers to a two times two randomized set of variables.
My first approach was as in the title: ${var${randnum}}.
As this did not work I developed it further with below result.

In the calculate field I write
concat('$','{','trust',${rand_no2},'_' ,${rand_no3_1},'}')
Which should result in
and respective combinations.

Without line 11 (name=ref2) the file compiles and I can start it in ODK. When I reach line 10, however, I receive the message:
"Error Occured
Dependency cycle in s; recursion limit exceeded!!"
(I included line two to show what I want to do in the end.)
example.xls (82.5 KB)

I am writing the file in Excel and compile it with ODK xlsform offline. (For testing I transfer it via cable to my phone.)

I am attaching the xls file for reproduction.

Thank you very much in advance!


You're mixing up some things related to the ${q} syntax, question names and question values.

Note that ODK Collect does not actually understand the ${q} syntax (which is XLSForm-only). It's helpful to look at the actual form format that ODK collect understands which is called XForm, an XML format that XLSForm converts into. However, even if ODK Collect understood the ${q} syntax, your approach still wouldn't work since you're creating a string value for the ref question (using concat). This wouldn't magically be evaluated as a reference / formula. You cannot dynamically create a reference or formula.

At the moment (until ODK supports something like the local-name() function), maybe the best approach is to use position and put the calculated values inside a group. Something like //group/calc[number(${pos})] perhaps. Note that positions are 1-based (so the first item is position 1) and casting the position to a number or integer is required.

Thank you Martijn. Thanks also for explaining the background of the different form formats (XForm vs. XLSForm). The key takeaway for me is that one "cannot dynamically create a reference or formula." In the end I could not find a solution as per your suggestion with position etc. Let's hope odk implements a function for dynamic references at some point.
(Apologies also for cross-posting on stackoverflow. I wanted to increase my chances for a response.)