title: Orbeon Form with repeated grid : Identify field values of same iteration
body: <p>I am using Form Builder (version 4.9) to create a form containing a Repeated Grid.
  I've also defined a Process button, in order to send the form's data to a Servlet (using the send() method).
  My goal is to save the form data in a DB table.</p>
  
  <p>I am able to receive the Form's data as XML in the servlet, but I noticed that a field having the same value in different iterations,
  appears only once per value in the XML, having a 'for' attribute with multiple values (indicating the number of the value repetitions).
  However, I haven't been able to find a way to match all fields of the same iteration (indicating one table row), so I am not able to store the data in the DB correctly.</p>
  
  <p>For Example , when I post the following table </p>
  
  <pre><code>HEADERS :   FIELD_B     -  FIELD_C      -
  ITER_1  :   FIELD_B_1   -  FIELD_C_1    -
  ITER_2  :   FIELD_B_2   -  FIELD_C_2    -
  ITER_2  :   FIELD_B_3   -  FIELD_C_1    -
  </code></pre>
  
  <p>I get the following XML </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;metadata&gt;
      &lt;control for="e7d2bb4ac261e77159fc236e7fd922c3540756f8" name="section-1"
          type="section"&gt;
          &lt;resources lang="en"&gt;
              &lt;label&gt;Untitled Section&lt;/label&gt;
          &lt;/resources&gt;
      &lt;/control&gt;
      &lt;control for="69ec5abdeb2df55c97bf5b1db46cce6bc841aed8" name="FIELD_A"
          type="input"&gt;
          &lt;resources lang="en"&gt;
              &lt;label&gt;FIELD_A&lt;/label&gt;
              &lt;hint /&gt;
          &lt;/resources&gt;
          &lt;value&gt;FIELD_A_V&lt;/value&gt;
      &lt;/control&gt;
      &lt;control for="9749b7620379db1e8f86eeceaf52c60fa19484d2" name="FIELD_B"
          type="input"&gt;
          &lt;resources lang="en"&gt;
              &lt;label&gt;FIELD_B&lt;/label&gt;
              &lt;hint /&gt;
          &lt;/resources&gt;
          &lt;value&gt;FIELD_B_1&lt;/value&gt;
      &lt;/control&gt;
      &lt;control
          for="89761405fd9de1a147bdda4d2c9279062b806016 9fa491ba6b72e86919e8a02226e28572c7309311"
          name="FIELD_C" type="input"&gt;
          &lt;resources lang="en"&gt;
              &lt;label&gt;FIELD_C&lt;/label&gt;
              &lt;hint /&gt;
          &lt;/resources&gt;
          &lt;value&gt;FIELD_C_1&lt;/value&gt;
      &lt;/control&gt;
      &lt;control for="9cf502968950de2af58236fe0aaaab2a4fa5ac6d" name="FIELD_B"
          type="input"&gt;
          &lt;resources lang="en"&gt;
              &lt;label&gt;FIELD_B&lt;/label&gt;
              &lt;hint /&gt;
          &lt;/resources&gt;
          &lt;value&gt;FIELD_B_2&lt;/value&gt;
      &lt;/control&gt;
      &lt;control for="46337304c26fca5cf9d5e91cdf393e3d39c0fbde" name="FIELD_C"
          type="input"&gt;
          &lt;resources lang="en"&gt;
              &lt;label&gt;FIELD_C&lt;/label&gt;
              &lt;hint /&gt;
          &lt;/resources&gt;
          &lt;value&gt;FIELD_C_2&lt;/value&gt;
      &lt;/control&gt;
      &lt;control for="1155463007588b06b3842c534ca678aa6f5cf665" name="FIELD_B"
          type="input"&gt;
          &lt;resources lang="en"&gt;
              &lt;label&gt;FIELD_B&lt;/label&gt;
              &lt;hint /&gt;
          &lt;/resources&gt;
          &lt;value&gt;FIELD_B_3&lt;/value&gt;
      &lt;/control&gt;
  &lt;/metadata&gt;
  </code></pre>
  
  <p>As you can see, in iterations 1 and 3, FIELD_C contains the value FIELD_C_1.
  When parsing the XML, I am not able to find the order of the values of that field. I end up with the incorrect table :</p>
  
  <pre><code>HEADERS :   FIELD_B     -  FIELD_C      -
  ITER_1  :   FIELD_B_1   -  FIELD_C_1    -
  ITER_2  :   FIELD_B_2   -  FIELD_C_1    -
  ITER_2  :   FIELD_B_3   -  FIELD_C_2    -
  </code></pre>
  
  <p>The iterations 2 and 3 have wrong values in FIELD_C.</p>
  
  <p>How can I find the correct order of the values for the repeated fields ?</p>
  
  <p>I am looking for a solution that does not require manipulating the form definition outside form builder,  since the forms will be created by the end user with no knowledge of XForms.</p>
  
  <p>The submit button in properties-local.xml is :</p>
  
  <pre><code>&lt;property
    as="xs:string"
    name="oxf.fr.detail.process.OrbeonFormsPortlet.*.*"&gt;
     validate-all
     then send(
           property = "oxf.fr.detail.send.success",
          uri = "http://localhost:8080/web/guest/testlang/-/oaed-form-requests/pop_up/{xxf:get-request-header('Orbeon-Liferay-User-Id')}",
          content = "metadata",
          prune = "false"
      )
  &lt;/property&gt;
  </code></pre>
  
  <p>The complete form definition is (the form contains a field - FIELD_A - outside repeated grid which is irrelevant to the problem):</p>
  
  <pre><code>&lt;xh:html xmlns:xh="http://www.w3.org/1999/xhtml"
           xmlns:xxi="http://orbeon.org/oxf/xml/xinclude"
           xmlns:ev="http://www.w3.org/2001/xml-events"
           xmlns:xi="http://www.w3.org/2001/XInclude"
           xmlns:saxon="http://saxon.sf.net/"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
           xmlns:fb="http://orbeon.org/oxf/xml/form-builder"
           xmlns:sql="http://orbeon.org/oxf/xml/sql"
           xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
           xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
           xmlns:xf="http://www.w3.org/2002/xforms"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:exf="http://www.exforms.org/exf/1-0"&gt;
      &lt;xh:head&gt;
          &lt;xh:title&gt;TestRepeat&lt;/xh:title&gt;
          &lt;xf:model id="fr-form-model" xxf:expose-xpath-types="true"&gt;
  
              &lt;!-- Main instance --&gt;
              &lt;xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all"&gt;
                  &lt;form&gt;
                      &lt;section-1&gt;
                          &lt;FIELD_A/&gt;
                          &lt;grid-3&gt;
                              &lt;grid-3-iteration&gt;
  
                                  &lt;FIELD_B/&gt;
                                  &lt;FIELD_C/&gt;
  
                              &lt;/grid-3-iteration&gt;
                          &lt;/grid-3&gt;
                      &lt;/section-1&gt;
                  &lt;/form&gt;
              &lt;/xf:instance&gt;
  
              &lt;!-- Bindings --&gt;
              &lt;xf:bind id="fr-form-binds" ref="instance('fr-form-instance')"&gt;
                  &lt;xf:bind id="section-1-bind" name="section-1" ref="section-1"&gt;
                      &lt;xf:bind id="FIELD_A-bind" name="FIELD_A" ref="FIELD_A"/&gt;
                      &lt;xf:bind id="grid-3-bind" ref="grid-3" name="grid-3"&gt;
                          &lt;xf:bind id="grid-3-iteration-bind" ref="grid-3-iteration" name="grid-3-iteration"&gt;
  
                              &lt;xf:bind id="FIELD_B-bind" ref="FIELD_B" name="FIELD_B"/&gt;
                              &lt;xf:bind id="FIELD_C-bind" ref="FIELD_C" name="FIELD_C"/&gt;
  
                          &lt;/xf:bind&gt;
                      &lt;/xf:bind&gt;
                  &lt;/xf:bind&gt;
              &lt;/xf:bind&gt;
  
              &lt;!-- Metadata --&gt;
              &lt;xf:instance xxf:readonly="true" id="fr-form-metadata" xxf:exclude-result-prefixes="#all"&gt;
                  &lt;metadata&gt;
                      &lt;application-name&gt;OAED&lt;/application-name&gt;
                      &lt;form-name&gt;TestRepeat&lt;/form-name&gt;
                      &lt;title xml:lang="en"&gt;TestRepeat&lt;/title&gt;
                      &lt;description xml:lang="en"/&gt;
                      &lt;singleton&gt;false&lt;/singleton&gt;
                  &lt;/metadata&gt;
              &lt;/xf:instance&gt;
  
              &lt;!-- Attachments --&gt;
              &lt;xf:instance id="fr-form-attachments" xxf:exclude-result-prefixes="#all"&gt;
                  &lt;attachments&gt;
                      &lt;css mediatype="text/css" filename="" size=""/&gt;
                      &lt;pdf mediatype="application/pdf" filename="" size=""/&gt;
                  &lt;/attachments&gt;
              &lt;/xf:instance&gt;
  
              &lt;!-- All form resources --&gt;
              &lt;!-- Don't make readonly by default in case a service modifies the resources --&gt;
              &lt;xf:instance id="fr-form-resources" xxf:readonly="false" xxf:exclude-result-prefixes="#all"&gt;
                  &lt;resources&gt;
                      &lt;resource xml:lang="en"&gt;
  
                          &lt;FIELD_B&gt;
                              &lt;label&gt;FIELD_B&lt;/label&gt;
                              &lt;hint/&gt;
                          &lt;/FIELD_B&gt;
                          &lt;FIELD_C&gt;
                              &lt;label&gt;FIELD_C&lt;/label&gt;
                              &lt;hint/&gt;
                          &lt;/FIELD_C&gt;
  
                          &lt;section-1&gt;
                              &lt;label&gt;Untitled Section&lt;/label&gt;
                          &lt;/section-1&gt;
                          &lt;FIELD_A&gt;
                              &lt;label&gt;FIELD_A&lt;/label&gt;
                              &lt;hint/&gt;
                          &lt;/FIELD_A&gt;
                      &lt;/resource&gt;
                  &lt;/resources&gt;
              &lt;/xf:instance&gt;
  
              &lt;!-- Utility instances for services --&gt;
              &lt;xf:instance id="fr-service-request-instance" xxf:exclude-result-prefixes="#all"&gt;
                  &lt;request/&gt;
              &lt;/xf:instance&gt;
              &lt;xf:instance id="fr-service-response-instance" xxf:exclude-result-prefixes="#all"&gt;
                  &lt;response/&gt;
              &lt;/xf:instance&gt;
              &lt;xf:instance xxf:readonly="true" id="grid-3-template"&gt;
                  &lt;grid-3-iteration&gt;
                      &lt;FIELD_B/&gt;
                      &lt;FIELD_C/&gt;
                  &lt;/grid-3-iteration&gt;
  
              &lt;/xf:instance&gt;
          &lt;/xf:model&gt;
      &lt;/xh:head&gt;
      &lt;xh:body&gt;
          &lt;fr:view&gt;
              &lt;fr:body xmlns:oxf="http://www.orbeon.com/oxf/processors"
                       xmlns:p="http://www.orbeon.com/oxf/pipeline"
                       xmlns:xbl="http://www.w3.org/ns/xbl"&gt;
                  &lt;fr:section id="section-1-control" bind="section-1-bind"&gt;
                      &lt;xf:label ref="$form-resources/section-1/label"/&gt;
                      &lt;fr:grid&gt;
                          &lt;xh:tr&gt;
                              &lt;xh:td&gt;
                                  &lt;xf:input id="FIELD_A-control" bind="FIELD_A-bind"&gt;
                                      &lt;xf:label ref="$form-resources/FIELD_A/label"/&gt;
                                      &lt;xf:hint ref="$form-resources/FIELD_A/hint"/&gt;
                                      &lt;xf:alert ref="$fr-resources/detail/labels/alert"/&gt;
  
                                  &lt;/xf:input&gt;
                              &lt;/xh:td&gt;
                              &lt;xh:td/&gt;
                          &lt;/xh:tr&gt;
                      &lt;/fr:grid&gt;
                      &lt;fr:grid id="grid-3-grid" bind="grid-3-bind" repeat="content" min="1"
                               template="instance('grid-3-template')"&gt;
                          &lt;xh:tr&gt;
  
                              &lt;xh:td&gt;
                                  &lt;xf:input id="FIELD_B-control" bind="FIELD_B-bind"&gt;
                                      &lt;xf:label ref="$form-resources/FIELD_B/label"/&gt;
                                      &lt;xf:hint ref="$form-resources/FIELD_B/hint"/&gt;
                                      &lt;xf:alert ref="$fr-resources/detail/labels/alert"/&gt;
  
                                  &lt;/xf:input&gt;
                              &lt;/xh:td&gt;
                              &lt;xh:td&gt;
                                  &lt;xf:input id="FIELD_C-control" bind="FIELD_C-bind"&gt;
                                      &lt;xf:label ref="$form-resources/FIELD_C/label"/&gt;
                                      &lt;xf:hint ref="$form-resources/FIELD_C/hint"/&gt;
                                      &lt;xf:alert ref="$fr-resources/detail/labels/alert"/&gt;
  
                                  &lt;/xf:input&gt;
                              &lt;/xh:td&gt;
  
                          &lt;/xh:tr&gt;
                      &lt;/fr:grid&gt;
                  &lt;/fr:section&gt;
              &lt;/fr:body&gt;
          &lt;/fr:view&gt;
      &lt;/xh:body&gt;
  &lt;/xh:html&gt;
  </code></pre>