2016-09-28 41 views
0

我正在使用XForms操作以及iterateiterate选择一组(使用XPath)的节点,并重复它的动作。问题是我有多个条件选择节点集。如何在XForms action元素的迭代中引用另一个实例?

  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> 

回答

0

这应该工作:

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

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

明确选择.../property/text()将不是必要的。

+0

不幸的是,没有工作。结果与以前一样。忽略属性仍然是结果的一部分。 – Crusaderpyro

+0

发布这是针对的XML。 – Tomalak

+0

我已经添加了示例目标XML。然而,我意识到name ='c_name'将会工作,并按照预期产生一个带有单个属性的结果,但not(name ='c_name')没有任何作用(期望总属性为-c_name)。你确定不是那部分? – Crusaderpyro

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) 
    ] 
"> 
相关问题