I created a form with a repeat to show a list of data.But not all row elements are from same nodeset! The table is created based the number of Student nodes:
...
<Student>
<Firstname>Kostas</Firstname>
<Lastname>Oikonomopoulos</Lastname>
</Student>
<Student>
<Firstname>Teo</Firstname>
<Lastname>Kartsonas</Lastname>
</Student>
...
<Math>
<Name>Mathematics</Name>
<Grade>Class A</Class>
</Math>
<Math>
<Name>Physics</Name>
<Class>Class B</Class>
</Math>
...
So i want to create a repeated grid like this:
Headers -Lastname- -Firstname- -Lesson- -Class-
1# ---- Oikonomopoulos ---- Kostas ---- Mathematics ---- Class A
2# ---- Kartsonas ---- Teo ---- Physics ---- Class B
Where the data list consists of each row for every student, and each student has a lesson and a class for this lesson based the relative position of the student!
So i want in each row:
//(Student)[i]/Firstname, //(Student)[i]/Lastname, //(Math)[i]/Name, //(Math)[i]/Class
where i
is the position of the each Student node iteration.
I create the data table using xf:repeat :
...
<xf:repeat ref="instance('fr-form-instance')//Student">
...
...
<xh:td>
<xf:output ref="Firstname"/>
</xh:td>
<xh:td>
<xf:output ref="Lastname"/>
</xh:td>
...
<xh:td>
<xf:output ref="(//Math)[position()]/Name"/>
</xh:td>
<xh:td>
<xf:output ref="(//Math)[position()]/Class"/>
</xh:td>
...
The students are shown as expected, but lessons and the classes have same values for all iterations!Like:
Headers -Lastname- -Firstname- -Lesson- -Class-
1# ---- Oikonomopoulos ---- Kostas ---- Mathematics ------------------ Class A
2# ---- Kartsonas ---- Teo ---- Mathematics (wrongValue!) ---- Class A (wrongValue!)
The weird thing is that if the position() alone as output in a column, correctly shows 1,2,...!?! I am using Orbeon 4.5
In the situation that the nodeset we want to refer are outside the repeated nodeset, the position() function doesn't work in calculations as i expected. Instead the solution was to use xxf:repeat-position() function!
So instead of,
<xf:output ref="(//Math)[position()]/Name"/>
, the proper way is:
<xf:output ref="(//Math)[xxf:repeat-position()]/Name"/>
xxf:repeat-position() function works in the UI
<xf:output value="xxf:repeat-position()"/>