In an XForms form, I have a section that repeats with inputs inside of it. There is a dropdown that will populate in each repeated section and no two dropdowns can have the same value selected. Each dropdown must have a unique selection and if there is a duplicate selection between dropdowns in the seperate sections they should become invalid.
This is the idea I am going for
constraint="not(. = instance('my-instance')/repeated-section[Include everything BUT .'s parent]/dropdown)"
Sample Instance Data:
<repeated-section>
<input1></input1>
<input2></input2>
<dropdown></dropdown>
<input4></input4>
</repeated-section>
<repeated-section>
<input1></input1>
<input2></input2>
<dropdown></dropdown>
<input4></input4>
</repeated-section>
<repeated-section>
<input1></input1>
<input2></input2>
<dropdown></dropdown>
<input4></input4>
</repeated-section>
This is mainly an XPath filtering question. Is it possible to do what I am asking? I want to compare the current node (lets say the 2nd set of the repeated-section) against all other repeated nodesets (repeated-section 1 and 3), excluding the current nodeset (because if you compare against all including the self, it will of course be compared to as true).
To simplify things, I assumed that you have just one element for each iteration of the repeat:
Then the constraint becomes:
One trick is in the
exceptkeyword, which allows you to build a sequence with all the “other repeat-value”. Then you want to know if any of those is equal to the current node, which you do with=operator. Finally, the node is valid, if you can’t find another node with the same value, hence thenot(). Note that usingnot(… = …)is not the same as… != …. And here is a full example to try this out: