Xpath 过滤重复节点集中除当前 Position() 之外的所有内容
在 XForms 表单中,我有一个重复的部分,其中包含输入。每个重复部分中都会填充一个下拉列表,并且任何两个下拉列表都不能选择相同的值。每个下拉列表必须有一个唯一的选择,如果单独部分中的下拉列表之间存在重复的选择,则它们应该无效。
这就是我对
constraint="not(. = instance('my-instance')/repeated-section[Include everything BUT .'s parent]/dropdown)"
示例实例数据的想法:
<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>
这主要是一个 XPath 过滤问题。可以按照我的要求做吗?我想将当前节点(假设重复部分的第二组)与所有其他重复节点集(重复部分 1 和 3)进行比较,不包括当前节点集(因为如果您与包括自身在内的所有节点集进行比较,它将当然要与真实的进行比较)。
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了简化事情,我假设重复的每次迭代只有一个元素:
然后约束变为:
一个技巧是
except
关键字,它允许您构建一个包含所有“的序列”其他重复值”。然后您想知道其中是否有任何一个等于当前节点,您可以使用=
运算符来执行此操作。最后,如果找不到具有相同值的另一个节点,则该节点有效,因此使用not()
。请注意,使用not(... = ...)
与... != ...
不同。这是一个完整的例子来尝试这个: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
except
keyword, 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: