0

我正在使用 XForms 动作和iterate. 选择iterate一组节点(使用 XPath)并为其重复操作。问题是我有多个选择节点集的条件。

  1. 不应该有readOnly节点。
  2. 不应该是ignoreProperties列表的一部分(此列表在另一个实例中)。

代码:

<xf:action ev:event="setValues" iterate="
    instance('allProps')/props/prop[
        not(readOnly) and
        not(instance('ignoreProperties')/ignoredProperties/property[text() = name]
    ]
">

第一个条件not(readOnly)有效。但第二个条件不起作用。我觉得 XPath 节点的上下文存在一些问题。

我应该如何替换第二个条件以达到结果?

目标 XML 是一个简单的ignoredProperties文档:

<ignoredProperties>
  <property>c_name</property>
  <property>c_tel_no</property>
</ignoredProperties>
4

2 回答 2

0

您对 的调用似乎有问题instance()。如果你有:

<xf:instance id="ignoredProperties">
    <ignoredProperties>
        <property>c_name</property>
        <property>c_tel_no</property>
    </ignoredProperties>
</xf:instance>

然后instance('ignoredProperties')返回<ignoredProperties>元素。所以你应该写:

<xf:action ev:event="setValues" iterate="
    instance('allProps')/prop[
        not(readOnly) and
        not(instance('ignoreProperties')/property[text() = name])
    ]
">

这也假设您的allProps实例具有<props>根元素。

此外,第二个条件似乎是错误的,如另一个答案所示。改为:

not(name = instance('ignoreProperties')/property)

在 XPath 2 中,您可以澄清您not()正在测试节点是否存在,empty()而是使用:

<xf:action ev:event="setValues" iterate="
    instance('allProps')/prop[
        empty(readOnly) and
        not(name = instance('ignoreProperties')/property)
    ]
">
于 2016-09-28T16:30:21.583 回答
0

这应该有效:

<xf:action ev:event="setValues" iterate="
    instance('allProps')/props/prop[
        not(readOnly) and
        not(name = instance('ignoreProperties')/ignoredProperties/property)
    ]
">

=运算符针对多个节点工作,返回所有匹配的节点。用not()你可以表达你不想要匹配。

.../property/text()不需要显式选择。

于 2016-09-28T07:29:37.247 回答