Using the current()/.. to reference a field in the repeat group example

Hi guys,

I've moved this from community to developers list, but adding additional
information here. I'm currently running with the newest ODK Collect 1.4.3
on Nexus 7 tab and i need help with this error "XPath evaluation: type
mismatch This field is repeated... You may need to use the indexed-repeat()
function to specify which value you want...".

Looking around the mailing list, it seems like the solution is by using the
current()/.. qualifier to an XPath expression. Is this already supported
with XLSForms? Does anyone have an xls file with this example, or point me
to some documentation.

Check out line from repeat group in the test_data.xml file attached.

Richard

test_data.xml (241 Bytes)

There isn't enough context here to answer your question.

The two mechanism for working with this error are to use indexed-repeat()
and to use the current()/... syntax, available in the latest ODK Collect
release.

··· ----------------

If you need to reference fields within a repeat group, within XLSForm, you
cannot use the ${fieldname} syntax, as it expands to an expression that
refers to all values for that one field, across all repetitions of the
enclosing repeat group(s).

Instead, you must use relative referencing, where you use ../../field2 to
move up two groups to access the value of field2, or, ../../alt2/field3 to
move up two groups, descend into the alt2 group, and select field3 in that
group.

The problem occurs when you want to use these relative references within
cascading select filters, e.g., consider a survey asking for a history of
all towns in which you've ever lived. This would have a repeat group where
you ask the user what state they live in (mystate), and then based upon
that answer, present a list of counties within that state. In the XML,
there would be a relative clause used within the towns cascading select
like:

instance('towns')/state[name=../mystate]/town

Here, the use of ../mystate will not work because the context from which it
starts is the instance('towns')/state context, rather than the form
submission data that you are gathering.

So you need to use current()/ to tell Javarosa to interpret the ../mystate
as referring to the form submission data. I.e.,

instance('towns')/state[name=current()/../mystate]/town


If you want to reference a field (field2) contained in a repeat group
(groupname) at some point later in the form, then the indexed-repeat()
expression can be useful. Here, you can do, e.g.,

indexed-repeat(${field2}, ${groupname}, 3)

Where you retrieve field2 from the 3rd repeat of the repeat group
'groupname' (field2 can be nested arbitrarily deeply within non-repeating
groups within 'groupname'). The nice thing here is that this uses XLS's
${fieldname} syntax.

This supports several layers of repeat-group nestings, so, for example:

indexed-repeat(${item_name}, ${household_members}, 4, ${owned_items}, 2)

would retrieve the name (item_name) of the 2nd item owned by the 4th member
of the household.

On Tue, Jul 15, 2014 at 10:49 AM, Ngamita Richard ngamita@gmail.com wrote:

Hi guys,

I've moved this from community to developers list, but adding additional
information here. I'm currently running with the newest ODK Collect 1.4.3
on Nexus 7 tab and i need help with this error "XPath evaluation: type
mismatch This field is repeated... You may need to use the indexed-repeat()
function to specify which value you want...".

Looking around the mailing list, it seems like the solution is by using
the current()/.. qualifier to an XPath expression. Is this already
supported with XLSForms? Does anyone have an xls file with this example, or
point me to some documentation.

Check out line from repeat group in the test_data.xml file attached.

Richard

--
You received this message because you are subscribed to the Google Groups
"ODK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit-developers+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

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

Hi Mitch,

Would you be so kind and share an XLSForm example in .xsl on how to use
current()/.. within position?

Richard

··· On Tuesday, July 15, 2014 8:49:27 PM UTC+3, Ngamita Richard wrote: > > Hi guys, > > I've moved this from community to developers list, but adding additional > information here. I'm currently running with the newest ODK Collect 1.4.3 > on Nexus 7 tab and i need help with this error "XPath evaluation: type > mismatch This field is repeated... You may need to use the indexed-repeat() > function to specify which value you want...". > > Looking around the mailing list, it seems like the solution is by using > the current()/.. qualifier to an XPath expression. Is this already > supported with XLSForms? Does anyone have an xls file with this example, or > point me to some documentation. > > Check out line from repeat group in the test_data.xml file attached. > > Richard >

Hi Mitch,

Please,I have the same problem and it would be great to have a sample XLS
form that shows how this can be done as mentioned below by Richard

Many Thanks

Adah

··· On Tuesday, July 15, 2014 10:32:44 PM UTC+1, Mitch wrote: > > There isn't enough context here to answer your question. > > The two mechanism for working with this error are to use indexed-repeat() > and to use the current()/... syntax, available in the latest ODK Collect > release. > > ---------------- > > If you need to reference fields within a repeat group, within XLSForm, you > cannot use the ${fieldname} syntax, as it expands to an expression that > refers to all values for that one field, across all repetitions of the > enclosing repeat group(s). > > Instead, you must use relative referencing, where you use ../../field2 to > move up two groups to access the value of field2, or, ../../alt2/field3 to > move up two groups, descend into the alt2 group, and select field3 in that > group. > > The problem occurs when you want to use these relative references within > cascading select filters, e.g., consider a survey asking for a history of > all towns in which you've ever lived. This would have a repeat group where > you ask the user what state they live in (mystate), and then based upon > that answer, present a list of counties within that state. In the XML, > there would be a relative clause used within the towns cascading select > like: > > instance('towns')/state[name=../mystate]/town > > Here, the use of ../mystate will not work because the context from which > it starts is the instance('towns')/state context, rather than the form > submission data that you are gathering. > > So you need to use current()/ to tell Javarosa to interpret the ../mystate > as referring to the form submission data. I.e., > > instance('towns')/state[name=current()/../mystate]/town > > -------------- > > If you want to reference a field (field2) contained in a repeat group > (groupname) at some point later in the form, then the indexed-repeat() > expression can be useful. Here, you can do, e.g., > > indexed-repeat(${field2}, ${groupname}, 3) > > Where you retrieve field2 from the 3rd repeat of the repeat group > 'groupname' (field2 can be nested arbitrarily deeply within non-repeating > groups within 'groupname'). The nice thing here is that this uses XLS's > ${fieldname} syntax. > > This supports several layers of repeat-group nestings, so, for example: > > indexed-repeat(${item_name}, ${household_members}, 4, ${owned_items}, 2) > > would retrieve the name (item_name) of the 2nd item owned by the 4th > member of the household. > > > > > On Tue, Jul 15, 2014 at 10:49 AM, Ngamita Richard <nga...@gmail.com > wrote: > >> Hi guys, >> >> I've moved this from community to developers list, but adding additional >> information here. I'm currently running with the newest ODK Collect 1.4.3 >> on Nexus 7 tab and i need help with this error "XPath evaluation: type >> mismatch This field is repeated... You may need to use the indexed-repeat() >> function to specify which value you want...". >> >> Looking around the mailing list, it seems like the solution is by using >> the current()/.. qualifier to an XPath expression. Is this already >> supported with XLSForms? Does anyone have an xls file with this example, or >> point me to some documentation. >> >> Check out line from repeat group in the test_data.xml file attached. >> >> Richard >> >> -- >> You received this message because you are subscribed to the Google Groups >> "ODK Developers" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to opendatakit-developers+unsubscribe@googlegroups.com >> . >> >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Mitch Sundt > Software Engineer > University of Washington > mitche...@gmail.com >

Has anyone gotten a clear example of this yet?

This is how we solve our problem with the error: "you may need to use the
indexed-repeat() function to specify which value you want."

The problem happen when, in a non repeating group, you apply to an internal
variable (A) a choice_filter where is present an another variable(B) that
is contained to the same group.

So, to solve the problem you have to put the current()/variable_name(B)
instead of the absolute path.

Did you understand?

Angelo

··· Il giorno venerdì 16 gennaio 2015 01:27:21 UTC+1, john....@grableservices.com ha scritto: > > Has anyone gotten a clear example of this yet?

I put an example XML for this together a while ago.

Sorry, I don't have an XLS version.

See attached.

new_dynamic_list.xml (6.36 KB)

··· On Fri, Jan 16, 2015 at 9:19 AM, Angelo Lazzari wrote:

This is how we solve our problem with the error: "you may need to use the
indexed-repeat() function to specify which value you want."

The problem happen when, in a non repeating group, you apply to an
internal variable (A) a choice_filter where is present an another
variable(B) that is contained to the same group.

So, to solve the problem you have to put the current()/variable_name(B)
instead of the absolute path.

Did you understand?

Angelo

Il giorno venerdì 16 gennaio 2015 01:27:21 UTC+1, john....@grableservices.com ha scritto:

Has anyone gotten a clear example of this yet?

--
You received this message because you are subscribed to the Google Groups
"ODK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

Hi Angelo!
I didn't understand!
Can you provide an xlsform example?

See https://opendatakit.org/help/form-design/#xpath_expressions

··· On Wed, Jun 15, 2016 at 1:25 AM, wrote:

Hi Angelo!
I didn't understand!
Can you provide an xlsform example?

--
You received this message because you are subscribed to the Google Groups
"ODK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

Also check out this bug
(https://groups.google.com/forum/#!searchin/opendatakit-developers/current()/opendatakit-developers/nN8HTA5pUIM/QVO7fnTqAQAJ)
or is this fixed in JavaRosa?

··· On Thursday, July 7, 2016 at 3:32:37 PM UTC-7, Mitch wrote: > > See https://opendatakit.org/help/form-design/#xpath_expressions > > On Wed, Jun 15, 2016 at 1:25 AM, <akhari...@ua.mercycorps.org > wrote: > >> Hi Angelo! >> I didn't understand! >> Can you provide an xlsform example? >> >> -- >> You received this message because you are subscribed to the Google Groups >> "ODK Developers" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to opendatakit-developers+unsubscribe@googlegroups.com >> . >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Mitch Sundt > Software Engineer > University of Washington > mitche...@gmail.com >

Correct. Still a bug.

··· On Thu, Jul 7, 2016 at 5:13 PM, Martijn van de Rijdt wrote:

Also check out this bug (
https://groups.google.com/forum/#!searchin/opendatakit-developers/current()/opendatakit-developers/nN8HTA5pUIM/QVO7fnTqAQAJ)
or is this fixed in JavaRosa?

On Thursday, July 7, 2016 at 3:32:37 PM UTC-7, Mitch wrote:

See https://opendatakit.org/help/form-design/#xpath_expressions

On Wed, Jun 15, 2016 at 1:25 AM, akhari...@ua.mercycorps.org wrote:

Hi Angelo!
I didn't understand!
Can you provide an xlsform example?

--
You received this message because you are subscribed to the Google
Groups "ODK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to opendatakit-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

--
Revolutionizing data collection since 2012.

Enketo https://enketo.org/ | LinkedIn
http://www.linkedin.com/company/enketo-llc | GitHub
https://github.com/enketo | Twitter https://twitter.com/enketo
| Blog http://blog.enketo.org/

--
You received this message because you are subscribed to the Google Groups
"ODK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

I have been trying to figure this out for awhile now. I understand the basic issue, but think I am having trouble with the syntax in the XLSform. I have attached a minimal example and am pretty sure that I need to replace:

${eat_hotdogs}= 'yes'

with something involving the update() function, but I cannot seem to get it to work. Could someone just post what to replace it with? (An equivalent XLSForm example would be swell)

If I need to know some complicated file path to get the correct answer, could someone also post a more detailed explanation of how to find the path. There should be very little path in the minimal example, I think, since there are no nested groups.

Matt

minimal_example.xlsx (11.1 KB)

Ok. I figured out my issue. The minimal file was actually fine. My error was coming elsewhere in the form.