[ODK Developers] Calculations within repeats

I believe it is a more serious problem with XPath evaluation. See
http://groups.google.com/group/opendatakit/browse_thread/thread/48fb8faeb39d027a/ff0f9bd7d175fceb?lnk=gst&q=xpath+evaluation#ff0f9bd7d175fceb

Your change would work as long as you never jumped back into the form via
the Hierarchy view. Otherwise, the size()-1 would be referring to the last
group entered, and not the group that is the true parent of the nested
group you're in.

Mitch

··· On Fri, Sep 21, 2012 at 3:55 PM, wrote:

I'd like to be able to run calculations on a form and do them within a
repeat. When going to the second repeat item on ODK Collect, JavaRosa has a
problem with trying to figure out what node to work with:

XPath Evaluation: type mismatch
nodeset has more than one node [...]; cannot convert to a value

A quick dive into JavaRosa and I notice that I can change this function:

org.javarosa.xpath.XPathNodeset.java:

    public Object unpack () {
            if (size() == 0) {
                    return XPathPathExpr.unpackValue(null);
            } else {
                    return getValAt(size()-1);
            }
    }

and everything will work properly. I figured there would be an issue when
going back and editing the form, but none found. Is there a reason why this
wouldn't be a fix for doing calculations within repeats? I'm sure I'm
missing something here but I can't seem to find where this will cause an
issue. Let me know if you find an issue with this.

Thanks,

Behr

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

Note: ODK Collect 1.2 now uses this fork of javarosa:
https://bitbucket.org/m.sundt/javarosa

Should you desire to submit a patch to fix this issue...

This branch has a fix for getting jr:count restrictions to work within
nested repeat groups. So it is starting to address these types of
issues....

Mitch

··· On Fri, Sep 21, 2012 at 4:21 PM, Mitch S wrote:

I believe it is a more serious problem with XPath evaluation. See
http://groups.google.com/group/opendatakit/browse_thread/thread/48fb8faeb39d027a/ff0f9bd7d175fceb?lnk=gst&q=xpath+evaluation#ff0f9bd7d175fceb

Your change would work as long as you never jumped back into the form via
the Hierarchy view. Otherwise, the size()-1 would be referring to the last
group entered, and not the group that is the true parent of the nested
group you're in.

Mitch

On Fri, Sep 21, 2012 at 3:55 PM, behratherton@gmail.com wrote:

I'd like to be able to run calculations on a form and do them within a
repeat. When going to the second repeat item on ODK Collect, JavaRosa has a
problem with trying to figure out what node to work with:

XPath Evaluation: type mismatch
nodeset has more than one node [...]; cannot convert to a value

A quick dive into JavaRosa and I notice that I can change this function:

org.javarosa.xpath.XPathNodeset.java:

    public Object unpack () {
            if (size() == 0) {
                    return XPathPathExpr.unpackValue(null);
            } else {
                    return getValAt(size()-1);
            }
    }

and everything will work properly. I figured there would be an issue when
going back and editing the form, but none found. Is there a reason why this
wouldn't be a fix for doing calculations within repeats? I'm sure I'm
missing something here but I can't seem to find where this will cause an
issue. Let me know if you find an issue with this.

Thanks,

Behr

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

Thanks for the replies Mitch!

I thought that is where I would find the problem but even after navigating
back it is still working fine on my version...Odd but oh well, I knew
something wasn't right here. I'll see what I can do to fully address the
issue and submit a patch.

Thanks again,
Behr

··· On Friday, September 21, 2012 5:21:16 PM UTC-6, Mitch wrote: > > I believe it is a more serious problem with XPath evaluation. See > http://groups.google.com/group/opendatakit/browse_thread/thread/48fb8faeb39d027a/ff0f9bd7d175fceb?lnk=gst&q=xpath+evaluation#ff0f9bd7d175fceb > > Your change would work as long as you never jumped back into the form via > the Hierarchy view. Otherwise, the size()-1 would be referring to the last > group entered, and not the group that is the true parent of the nested > group you're in. > > Mitch > > On Fri, Sep 21, 2012 at 3:55 PM, <behrat...@gmail.com >wrote: > >> I'd like to be able to run calculations on a form and do them within a >> repeat. When going to the second repeat item on ODK Collect, JavaRosa has a >> problem with trying to figure out what node to work with: >> >> XPath Evaluation: type mismatch >> nodeset has more than one node [...]; cannot convert to a value >> >> A quick dive into JavaRosa and I notice that I can change this function: >> >> org.javarosa.xpath.XPathNodeset.java: >> >> public Object unpack () { >> if (size() == 0) { >> return XPathPathExpr.unpackValue(null); >> } else { >> return getValAt(size()-1); >> } >> } >> >> and everything will work properly. I figured there would be an issue when >> going back and editing the form, but none found. Is there a reason why this >> wouldn't be a fix for doing calculations within repeats? I'm sure I'm >> missing something here but I can't seem to find where this will cause an >> issue. Let me know if you find an issue with this. >> >> Thanks, >> >> Behr >> > > > > -- > Mitch Sundt > Software Engineer > University of Washington > mitche...@gmail.com >