Current()/../field_name not working

1. What is the problem? Be very detailed.
I have a very simple form with a single repeat with a cascading select. When I use current()/../field_name as a choice filter on my second select no choices appear. If I skip the current() and just set the choice filter to the field I get an XPath error suggesting the use of indexed-repeat (which also does not work).

2. What app or server are you using and on what device and operating system? Include version numbers.
ODK Collect v1.22.0

3. What you have you tried to fix the problem?
Everything suggested on the forums.

4. What steps can we take to reproduce the problem?
See attached
test.xlsx (38.1 KB) test.xml (138.1 KB)

5. Anything else we should know or have? If you have a test form or screenshots or logs, attach below.

Figured it out, required current()/../../group_name/field_name

1 Like

For anyone running into a similar issue, the ../ goes up one level of nesting, starting with the current node. Because you have a repeat with a group nested in it and then your question with the choice filter, you need to go up two levels: out of the question and then out of the group.

Did you try just using ${compliance_category} in your choice filter instead of the current() expression? I believe the latest versions of the XLSForm converters should automatically convert that to a current() expression.

1 Like

Thanks LN! I think the pathing sequence is what confused us. current()/../field_name worked fine when the two questions were in the same group, which wasn't intuitive. Since ../ goes up one level of nesting, why would it be needed when the two questions were within the same group? Does one have to go "up and out" of a question node to access another question? If that were true, then one would never be able to refer to another field with ${field_name}.

I think it would be very helpful to have a paragraph in the documentation that explains how the pathing works. In my situation with two groups within a repeat I had assumed that ../ would take me outside of the 2nd group but remain inside the repeat, and that ../../ would be required to access questions outside of the repeat. Yet that was what was needed to access the other group inside the same repeat.

Long story short, it was not clear that ../ kept me within the group, and was needed just to move away from itself, in a sense.

I did indeed try using simply ${compliance_category} in my choice filter and it gave me an XPath error with the suggestion for needing indexed-repeat. I messed about with that for awhile and never got it to work (no error but no choices returned). Didn't make sense to use it since both questions were within the same repeat, and it was not a nested repeat.

Thanks again!

The full path of the node you have your choice filter on is /test/r1/g3/compliance_condition and that is what current() evaluates to.

/test/r1/g3/compliance_condition/../field_name corresponds to /test/r1/g3/field_name
/test/r1/g3/compliance_condition/../../field_name corresponds to /test/r1/field_name

Does that make sense?

I just tried ${compliance_category} using to do the conversion and ODK 1.22. It does seem to expand as expected and work in Collect. What versions of XLSForm and Collect are you using?

My hope is that this now Just Works™️ from XLSForm.

Thank you so much for helping me! Unfortunately I'm still a bit stumped.
/test/r1/g3/compliance_condition IS the field_name (/test/r1/g3/field_name). Why would it need to go up a level to access itself?

Since both groups are within the same repeat what seems intuitive to me is to merely go out one level (outside the current group) and into the next: current()/../g2/compliance_category

But I get that the syntax has changed and am happy to keep rolling with what we've figured out!

EDIT I did try the test again simply using ${compliance_category} as the choice filter but it did not return any choices under Permit Conditions (compliance_conditions field). Testing on ODK Collect v1.22.4 using pyxform at command line for the conversion.

I'm sorry, I didn't see that you had to add group_name in your expression. Indeed, that doesn't look right and there might be a Collect bug. I will try to dig deeper into it soon and get back to you.

No worries! I look forward to hearing about what you've discovered.

You mentioned that the two questions are in different groups but I missed that in my initial explanation.

You need to include the group name because compliance_category is in the g2 group and compliance_condition is in the g3 group. So when you use current()/../../g2/compliance_category as a choice filter for compliance_condition, current() is expanded to /test/r1/g3/compliance_condition which results in:

/test/r1/g3/compliance_condition/../../g2/compliance_category => /test/r1/g2/compliance_category

You can see that the first ../ goes "out of" the question node because current() evaluates to the full path of that node including its name.

I simplified your form a bit to test-hm20190708.xlsx (30.6 KB) and wrote the choice filter as comp_category = ${compliance_category}. I verified that pyxform correctly writes the choice filter as comp_category = current()/../../g2/compliance_category and that Collect shows the expected choices. Is it possible that the problem was caused by not having the comp_category = part? It's not clear to me why writing your own current() expression would address that, though.