SEL-Columbia / pyxform

A Python package to create XForms for ODK Collect.
21 stars 9 forks source link

translate ${name} inside a repeat to ../relative/path/to/node #91

Open MartijnR opened 11 years ago

MartijnR commented 11 years ago

One day this will have to happen... so I'm putting this here. It relates to a long-standing javarosa bug: https://bitbucket.org/javarosa/javarosa/wiki/XFormDeviations#!model-item-property-xpaths-are-always-evaluated-in-the-context-of-the-nodeset. Seems like pyxforms could take the lead in starting to do this correctly! It will avoid the 'position-injection' hack that is currently required for evaluating absolute paths inside repeats, improve performance significantly for some forms, and reduce code ugliness.

type             | name           | constraint
----------------------------------------------------------
begin_repeat     | rep            |  
text             | A              |
text             | B              | ${A} = 'something'
end_repeat       |                |

${a} in this case should become "../A" instead of "/data/rep/A" because the absolute "/data/rep/A" in pure un-hacked XPath always returns the value of the A node in the first repeat (even if the context is the 100th repeat).

nathanathan commented 11 years ago

I'm wondering if there is ever a reason to generate absolute paths. Switching to relative paths like this would definitely simplify the code.

MartijnR commented 11 years ago

Glad to hear that! It would simplify enketo too as the workaround is messy and buggy.

There should be no reason to ever want absolute paths when referring to a node inside a repeat from another in the same repeat. I believe it's just something that happened long time ago in the early JavaRosa libs and was never corrected (so there are many forms out there that have these incorrect XPaths).

nathanathan commented 11 years ago

Now that I've thought about this a bit more, I've realized it's necessary to add some notion of scope to the pyxform so that the correct relative paths can be computed from ${variable}s to reference values nested at different levels. So, never-mind what I said about it simplifying things in pyxform, although I think variable scope might be nice to have.

MartijnR commented 11 years ago

Right, I can see that it gets more tricky with nested groups/repeats. I hope you'll come up with a way to do this, as it would be great to push this forward.