0
votes

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

1
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. w3.org/TR/xforms20/#The_var_element - James Cockayne
Another option, which should be supported in xforms 1.0 is to use the index function 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"/> - James Cockayne
Thanks, @james-cockayne, I used xf:var and its working - Ganesh Mulay
Please you post as an answer, I will upvote to this. - Ganesh Mulay
Glad to hear it works! I think personally I'd use the 2nd solution (if it works, please let me know). I think you'll have fewer problems using the index function - James Cockayne

1 Answers

1
votes

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"/>