Open MartijnR opened 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.
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).
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.
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.
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.
${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).