Search code examples
xsltxforms

XFORMS: Issue while using nested (xf:repeat) with 2 different instance


There is Issue while using nested (xf:repeat) with 2 different instances.

<xf:repeat nodeset="instance('roomdetails-instance')/rooms/room/" id="room">                        
    <xf:repeat nodeset="instance('tapechart-instance')/bookings/booking/" id="book">
            <xf:output ref="roomNo"/> //This is from first instance
            <xf:output ref="name"/> //This is form second instance
    </xf:repeat>
</xf:repeat>

The second instance is working fine but and the first instance is not print anything

I am stuck here from last 2 days. please provide me the solution.

Thanks in advance


Solution

  • The trouble here is that the inner xf:repeat changes the context for the inner xf:output expressions. It changes the ref expressions of the output elements to be something along the lines of instance('tapechart-instance')/bookings/booking/roomNo and instance('tapechart-instance')/bookings/booking/name.

    You might be able to use xf:var to define a variable in the outside repeat that contains the roomNo value for the given iteration. Although this is from xforms 2.0 which isn't widely supported. https://www.w3.org/TR/xforms20/#The_var_element

    Another option, that should be supported in xforms 1.0 is to use the index function https://www.w3.org/TR/xforms/#fn-index.

    You could try changing <xf:output ref="roomNo"/> to something like this <xf:output ref="instance('roomdetails-instance')/rooms/room[index('room')]/roomNo"/>