kobotoolbox/enketo-express

indexed-repeat() not working in XPath predicate?

joeflack4 opened this issue · 4 comments

Description

I have a repeat group. Then, I have a question which has a dynamic list of options that populate from what is entered in that repeat group. Works fine in ODK Collect, but not in Enketo. There doesn't appear to be a way to declare my repeat group "finished" so that it can properly render my multiple choice question.

screen shot 2018-09-08 at 8 34 05 pm

Additional info

I've attached a zip file. The v2 file converts fine and can be loaded on Enketo. V3 is the same as v2, only it can also be uploaded to ODK Aggregate.

AUTO-v2_and_v3.zip

Thanks Joe,

Wow, that's quite an operation you've got going there! It's very hard to wrap my head around it but you are probably right that it is a bug (with using indexed-repeat() in a choice_filter). Will check it out (but probably not any time soon).

What this shows (apart from a possible bug) is that we should find a way to simplify creating a choice list from repeated answers in the same form in XLSForm. It is extraordinarily simple in XForms. See this simplified version of your XForm:

AUTO-v3-jef-simplified.xml.txt

The magic is just this:

    <select appearance="compact" ref="/AUTO-v3-jef/people_1">
        <label>Select people:</label>
        <itemset nodeset="/AUTO-v3-jef/member_info[./age &gt;= 18]">
            <value ref="member_name"/>
            <label ref="member_name"/>
        </itemset>
    </select>

This avoids using a secondary instance altogether (and all those calculations). If you'd want <value> to an index, you could add a calculation in the repeat and change the ref attribute.

Forgot to mention that Enketo updates everything in realtime (even across pages), so there is no 'Finished' state wrt repeats creation.

This issue was moved to enketo/enketo#240

That query syntax [./age &gt;= 18] looks great. I first saw this syntax on an ODK Community forum post recently; maybe it was you that posted it. But yeah, it's not supported by the ODK XForm spec / XLSForms currently. When building such logic, I have some special tactics that I use; external text editors using find/replace and multiline cursors, using complicated intermediate Excel functions to do incrementation and interpolations. All kinds of fun.

Thanks for the clarification on the real-time rendering as well.