2016-09-28 50 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) 
    ] 
"> 
相關問題