Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MartijnR opened this issue Apr 10, 2013 · 4 comments
Open

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

MartijnR opened this issue Apr 10, 2013 · 4 comments

Comments

@MartijnR
Copy link

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
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants