如何在XForms动作元素的迭代中引用另一个实例?

时间:2016-09-28 07:14:08

标签: xpath orbeon xforms xpath-2.0 xsltforms

我正在使用XForms操作以及iterateiterate选择一组(使用XPath)节点并为其重复操作。问题是我有多个条件来选择节点集。

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

    <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>
    

2 个答案:

答案 0 :(得分:0)

这应该有效:

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

=运算符对多个节点起作用,返回所有匹配的节点。使用not(),您可以表示您不希望匹配。

无需明确选择.../property/text()

答案 1 :(得分: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)
    ]
">
相关问题