XML - Xpath iterating through a list. Enketo works great but ODK collect shows error

Hi, I have recently started to use Xpath to load data from external CSV files in a more flexible way but have found that while the results on Enketo are great, ODK Collect throws an error. I am able to use XML to create the list of values I need but when I try to iterate through this list from within a repeat group I get errors.

Whenever I refer to the repeat group position (position(..)) I get an error telling me to use the indexed-repeat function. This is unexpected as the calculation is already inside the only repeat group in the form.

Whenever I try to simplify the Xpath I get no error but also no result from the calculation:

If anyone knows the correct syntax to use when iterating through a list from a CSV file that would be greatly appreciated.

name[1] really means name[position() = 1]. the position() = 1 part is an XPath predicate and 1 is a special shortcut usage.

The full predicate position() = ${repeat_group_position} should do what you're looking for in all clients.

Hi Helene,

Thanks so much for the response as this really goes beyond my knowledge.
When I use name[${repeat_position}] it doesn't work for me on Enketo but name[position() = ${repeat_position} does work as expected (see webform link). When testing on ODK collect however neither syntax seem to work as expected. I get the below error:

In case useful I have attached the short test form with the Xpath calculation below and a small accompanying csv file.
XPATH_TEST.xlsx (32.7 KB)
external_choices_xpath.csv (88 Bytes)

I couldn't figure out how to avoid this error as it seemed strange to me to try to use an indexed-repeat for a calculation which refers only to a previous question which is already contained in the same repeat group. Is there any chance that the error message is being triggered unnecessarily or that I can reference the repeat group position in another way?

As always, any guidance you can give is much appreciated.


Seems that the correct syntax needed to be as below:

I needed to specify the position of the node at "item" level and not name (not sure why "name" level worked on enketo as "name" is just a random csv column header). As I had a second filter criteria I had to place it before the position criteria (otherwise the positioning made no sense) so the result was something like this:


Thanks so much @LN as your response let me know I was on the right track and I would have given up troubleshooting otherwise. If there is anywhere I should look for resources to learn more about xml in relation to ODK I will happily do some reading.