xforms - 与 OR 条件相关

发布于 2025-01-01 00:28:10 字数 312 浏览 4 评论 0原文

(我刚刚开始使用 xforms)

我有一个带有 10 个整数输入字段和 1 个文本字段的表单 我正在尝试在文本字段上设置相关标准。 我想要做的是当且仅当一个或多个字段的值高于 18 时才显示文本字段。

我相信我需要在相关字段中使用 or 条件,例如: related="(/data/weight_group/weight1 > 18 || /data/weight_group/weight2 > 18)"

显然这并不完全正确,但我在 Google/Stack/等上找不到任何接近的东西,导致我相信我找错了树。

有什么建议吗? 谢谢

(I'm just starting out with xforms)

I have a form with 10 integer entry fields and 1 text field
I'm trying to set a relevant criteria on a text field.
What I want to do is display the text field if and only if the value of one or more of the fields is higher than 18.

I believe I need an or condition in the relevant field, something like:
relevant="(/data/weight_group/weight1 > 18 || /data/weight_group/weight2 > 18)"

Obviously that's not exactly right, but I can't find anything even close on Google/Stack/etc., leading me to believe that I'm barking up the wrong tree.

Any suggestions?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凤舞天涯 2025-01-08 00:28:10

应该是这样的:

relevant="/data/weight_group/weight1 < 18 or /data/weight_group/weight2 > 18"

一些解释:

  • 相关属性的值是 XPath 表达式。因此,当出现问题时,您需要查阅 XPath 文档。
  • XPath 中的逻辑运算符是“and”和“or”,而不是“&&”和“||”。
  • 你需要逃离<和>在 XPath 表达式中为 <和 >,这样它们就不会弄乱 XML 结构。 (有人可以证实一下吗?)

It should be something like this:

relevant="/data/weight_group/weight1 < 18 or /data/weight_group/weight2 > 18"

Some explanations:

  • The value of relevant property is XPath expression. So you need to consult XPath documentation when something doesn't work.
  • Logical operators in XPath are "and" and "or", not "&&" and "||".
  • You need to escape < and > in XPath expressions as < and >, so that they don't mess up the XML structure. (Can someone confirm this?)
神仙妹妹 2025-01-08 00:28:10

首先,相关属性是模型属性,这意味着它不适用于控件。其次,它通过绑定元素进行更新。

<model  xmlns="http://www.w3.org/2002/xforms">
  <instance>
     <data xmlns="">
        <weight_group>
           <weight1/><weight2/>
        </weight_group>
        <valid_weight>
     </data>
  </instance>
  <bind nodeset="/data/valid_weight" relevant="../weight_group/weight1 < 18 or ../weight_group/weight2 > 18">
</model>

valid_weight 属性受此条件控制,任何绑定到有效权重的控件在不相关时都会消失。

Firstly the relevant property is a model property, that means it does not work on the controls. Secondly it is updated via a bind element.

<model  xmlns="http://www.w3.org/2002/xforms">
  <instance>
     <data xmlns="">
        <weight_group>
           <weight1/><weight2/>
        </weight_group>
        <valid_weight>
     </data>
  </instance>
  <bind nodeset="/data/valid_weight" relevant="../weight_group/weight1 < 18 or ../weight_group/weight2 > 18">
</model>

To the property valid_weight is controlled by this condition, and any control bound to valid weight will disappear when not relevant.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文