XLSForm / pyxform

A Python package to create XForms for ODK Collect.
BSD 2-Clause "Simplified" License
77 stars 134 forks source link

Wrong reference when building select one from repeat inside that repeat #503

Closed lognaturel closed 3 years ago

lognaturel commented 3 years ago

Software and hardware versions

pyxform v1.3.3

Problem description

When trying to use a select one from repeat inside the current repeat, the wrong reference is produced. It should be ../../repeat but instead is ../.

Steps to reproduce the problem

type name label choice_filter appearance relevance calculation
begin_repeat pet Pet   field-list    
calculate pos         position(..)
select_one ${animal_type} animal_select Select the animal type. If not in the list, type below. position() != current()/../pos and animal_type != ''      
text animal_type Animal type     ${animal_select} = ''  
end_repeat pet          

XLSForm

    def test_choice_from_previous_repeat_in_current_repeat__parents_out_to_repeat(self):
        xlsform_md = """
        | survey  |                           |                           |                          |
        |         | type                      | name                      | label                    |
        |         | begin repeat              | pet                       | Pet                      |
        |         | select_one ${animal_type} | animal_select             | Select the animal type   |
        |         | text                      | animal_type               | Specify the animal type  |
        |         | end repeat                | pet                       |                          |
        """
        self.assertPyxformXform(
            name="data",
            debug=True,
            md=xlsform_md,
            xml__contains=[
                '<itemset nodeset="../../pet">',
            ],
        )
DavisRayM commented 3 years ago

I'd like to pick this up...

lognaturel commented 3 years ago

Thanks for picking this up, @DavisRayM! I realize it's worth a little more high-level discussion in light of #525. Both deal with how to expand repeat references that appear inside that same repeat.

@MartijnR this is kind of a fake open select that users try to use. It seems reasonable to me and like something we should support. What do you think? Do you see it as exactly the same case as #525? They feel distinct to me because in the context of a select from repeat there's no ambiguity about user intent whereas I think there is in the #525 cases. Additionally, there's no way to write a raw XPath expression to clarify intent because the select_one syntax doesn't allow it.

Here we could also generate an absolute ref to /data/pet instead of my proposed ../../pet. I know people want to do this in nested repeats which is why the relative expression is more appealing to me.

MartijnR commented 3 years ago

I see no problem with this. It does seem similar to #525, and makes me think #525 could also be this kind of relative reference that first steps outside of the repeat (to support nested repeats), but I will respond in that issue.