Relevence Condition with Multiple Repeats

All right, I admit defeat.

My goal is simple: I want to have a question filter based upon an answer to
a different question, in a different group, in the current repeat group. I
for the life of me can't figure out how to get this work. Here is the
relevance filter I wrote:

/slimmed/r1[position(current()/..)]/g3/sample_unit = 'floating_unit'

Which I figured would evaluate on a path like:

/slimmed/r1[1]/g3/sample_unit = 'floating_unit'

But when I actually test the form, the relevancy filter is never
satisfied. Do I need an indexed-repeat or something? I can't really wrap
my mind around how indexed-repeat works, so can someone give me an
example? I have attached a form example.

slimmed.xlsx (16.6 KB)

slimmed(9).xml (9.33 KB)

You don;'need the xpath code, you just need to call the variable name since
you are within the same repeat.

I tested it and it worked for me, make sure to add a repeat count to your
loop, it sometimes confuses the users.

Best Regards,
-Hanan

slimmed.xlsx (16.5 KB)

In general: any reference to a field that is defined within a repeat group
by using the XLSForm ${fieldname} syntax will be incorrect and will break.

I.e., if you have a field 'myfield' within a repeat group, you cannot, in
general, refer to it with ${myfield}.

ยทยทยท ====================================================

Whenever you are testing a form with a repeat group, or referencing any
variable within a repeat group, you need to verify that everything works
when you have 2 or more instances of that repeat group. If you use the ${}
syntax to refer to fields within the repeat group, your form will generally
break.

The exceptions are if you are using those references within:
indexed-repeat()
concat()
join()
count()
sum()
max()
min()

====================================================

In this case, you have made two references to fields: ${sample_unit} and
${artifact_type}, that are each within repeat groups, and, since these
usages are not within the above 7 special functions, these usages are
incorrect.

Instead, in these cases, you need to use XPath expressions to reference
these fields. In most cases, these are simple relative names, using '../'
to move up a level in your form.

You generally don't need to prefix these with current()/ or use index
notation and wrap them inside position() unless you are using the value of
those fields within a filter condition for a choices list.

====================================================

(1) for the subsurface field within the repeat group, you need a
relevant condition that is dependent upon the value of sample_unit.

Looking at the XML structure (from the XML file):

      <r1 jr:template="">
        <g3>
          <sample_unit/>
        </g3>
        <g4>
          <subsurface/>
        </g4>

So when we reference sample_unit in the relevant condition
for subsurface within this repeat group, we need to construct a relative
path to that field instead of using ${} syntax.

In this case, for the subsurface field, we would use '../' to get up to the
field list group, then another '../' to get up to the repeat
group, and then append 'g3/' to get down into the field list group,
and then append 'sample_unit' to get to the value of sample_unit within
this same repeat group. The final expression (without any single quotes) is
then:
../../g3/sample_unit
and the relevant condition in the XLS would be:
../../g3/sample_unit = 'feature' or
../../g3/sample_unit = 'surface_artifact' or
../../g3/sample_unit = 'sample_unit' or
../../g3/sample_unit = 'other'

(2) for the nested repeat group at the bottom of the form, you have a
repeat group that collects artifact_type, and then a field-list that
displays questions based upon the answer to artifact_type.

In this case, within this repeat, we have an XML structure (from the XML
file):

        <r2 jr:template="">
          <artifact_type/>
          <g9>
            <artifact_flake_stone/>
            <artifact_gs/>
            <artifact_pre_crmc/>
          </g9>
        </r2>

So when we reference artifact_type in the relevant condition for those
other fields within this repeat group, we need to construct a relative path
to that field instead of using ${} syntax.

In this case, for the artifact_flake_stone field, we would use '../' to get
up to the field list group, then another '../' to get up to the
repeat group, and then append 'artifact_type' to get to the value of
artifact_type within this same repeat group. The final expression (without
any single quotes) is then:
../../artifact_type

and the relevant condition in the XLS would be:

selected(../../artifact_type, 'flake_stone')

instead of

selected(${artifact_type}, 'flake_stone')

Mitch

On Wed, Oct 21, 2015 at 2:17 AM, Hanan Aqilan hjameelq@gmail.com wrote:

You don;'need the xpath code, you just need to call the variable name
since you are within the same repeat.

I tested it and it worked for me, make sure to add a repeat count to your
loop, it sometimes confuses the users.

Best Regards,
-Hanan

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


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

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