Proposal: customize name and label 'columns' in selects from external data in XLSForm

This is the revised proposal that includes translation support that @LN and I have come up with and want to present for further discussion. It includes additional label parameters with a language code (e.g. label_en, label_fr) as shown in this example:

type name label::English (en) label::French (fr) parameters
select_one_from_file my_data.csv tree Tree Arbre value=id label_en=species label_fr=espèces

It works the same with XML external data files. It also works with choice_filters (so unchanged).

Compared to Enketo's rogue feature mentioned above this proposal does not require a specific CSV data structure, except that column headings should (ideally) be valid XML node names (we could work around that limitation though). So it provides the ultimate CSV flexibility. A small disadvantage is that it wouldn't work with XML files that use e.g lang attributes to provide translations. However, since we require a specific XML structure (root > item) for select_from_file anyway, that does not seem a big deal.

The earlier example without translations remains unchanged.

Pyxform would produce the following output (ignore this if you're not an XForm enthusiast or developer):

<itext>
    <translation default="true()" lang="English (en)">
        <text id="external_instance-my_data-0">
            <value>species</value>
        </text>
    </translation>
    <translation lang="French (fr)">
        <text id="external_instance-my_data-0">
            <value>espèces</value>
        </text>
    </translation>
</itext>
...
<instance id="my_data" src="jr://file-csv/mydata.csv" />
...
<itemset nodeset="instance('my_data')/root/item">
    <value ref="./id"/>
    <label ref="./*[local-name() = jr:itext('external_instance-my_data-0')]"/>
</itemset>

The reason for introducing local-name() instead of name() is to provide better support for external XML data which will likely be name-spaced. local-name() will ignore the namespace prefix.

(Not 100% sure if this ref value is XForms-compliant. Tbc.)

Any feedback would be very welcome!

P.S. Thanks @LN! Note, that I made a few tweaks to change parameter name back to value in XLSForm, use * instead of node() and changed the example to not use label but label_en.

1 Like