I have a requirement like i have 3 sets of itemsets(A,B and C) that neeed to be coming under a dropdown. and each itemset is selected based on some condition as shown below.
<xxforms:variable name="itemset-A-cnt" select="count(instance('data')/nodeA)" />
<xforms:group ref=".[condition for itemset A]">
<xforms:select1 ref="." incremental="true" appearance="minimal">
<xforms:itemset ref="instance('data')/nodeA"> <!--itemset A displayed if some if condition is true-->
<xforms:label ref="@key" />
<xforms:value ref="@key" />
</xforms:itemset>
</xforms:select1>
</xforms:group>
<xxforms:variable name="itemset-B-cnt" select="count(instance('data')/nodeB)" />
<xforms:group ref=".[condition for itemset B]">
<xforms:select1 ref="." incremental="true" appearance="minimal">
<xforms:itemset ref="instance('data')/nodeB"> <!--itemset B displayed if some if condition is true-->
<xforms:label ref="@key" />
<xforms:value ref="@key" />
</xforms:itemseif if t>
</xforms:select1>
</xforms:group>
<xforms:group ref=".[$itemset-A-cnt =0 and $itemset-B-cnt =0]">
<xforms:select1 ref="." incremental="true" appearance="minimal">
<xforms:itemset ref="instance('data')/nodeC"> <!--itemset C displayed if itemset A and B is empty-->
<xforms:label ref="@key" />
<xforms:value ref="@key" />
</xforms:itemset>
</xforms:select1>
</xforms:group>
Currently how we achieved this is using group with condition for Itemset A and Itemset B For itemset C. I found the count of values in the itemset A and B assigned it to variables a-cnt and b_cnt using xxforms:variable and created a group for itemset C with a size check.
The logic works for me. But I think this is not the right way to achieve something like this. If there is a way to put something like xxforms:if on the itemset, then I could do the logic in a single select1.
In XForms there is no limitation on the number of xforms:item
or xforms:itemset
you can use within a select
or select1
. Further you can control the set of items using a condition, for example with if (condition) then items else ()
.
So the solution would look like:
<xforms:select1>
<xforms:itemset nodeset="if (condition A) then instance('data')/nodeA else ()">
...
</xforms:itemset>
<xforms:itemset nodeset="if (condition B) then instance('data')/nodeB else ()">
...
</xforms:itemset>
<xforms:itemset nodeset="if (condition C) then instance('data')/nodeC else ()">
...
</xforms:itemset>
</xforms:select1>