2012-09-28 25 views
1

篩選項目。的情況是,我有一個綁定到一個實例複選框,實例被定義爲:Orbeon的XForms:基於我有過濾用Orbeon的XForms項問題複選框

<xf:instance id="Include-model"> 
    <data> 
     <value type="xs:string">true</value> 
    </data> 
</xf:instance> 

和複選框被聲明爲:

<xf:select ref="instance('Include-model')/value" selection="closed" appearance="full" > 
    <xf:item> 
     <xf:label>Include all</xf:label> 
     <xf:value>true</xf:value> 
    </xf:item> 
</xf:select> 

所以複選框被初步遏制。

現在我已經定義爲另一個實例的項目清單:

<xf:instance id="items-model"> 
    <Items> 
     <Item> 
      <value>1</value> 
      <status>Show</status>  
     </Item> 
     <Item> 
      <value>2</value> 
      <status>Show</status>  
     </Item> 
     <Item> 
      <value>3</value> 
      <status>Hide</status>  
     </Item> 
    </Items> 
</xf:instance> 

和相關的綁定:

<xforms:bind id="items-bind" nodeset="instance('items-model')Items/Item"> 

,顯示這些項目爲轉發

<xforms:repeat bind="items-bind" appearance="xxforms:internal"> 
    ..... 

我需要的是能夠根據複選框的狀態過濾項目。如果它檢查則綁定應該包括所有項目,它是否被選中的綁定只應包含具有「顯示」爲價值觀,如果他們的狀態元素的項目。

請幫幫忙,救我什麼小頭髮,我已經離開了。

TIA

回答

3

首先,讓我們擺脫了幾個問題:

<xforms:bind id="items-bind" nodeset="instance('items-model')Items/Item"> 

不是一個正確的XPath表達式。改用:

<xforms:bind id="items-bind" nodeset="instance('items-model')/Item"> 

指向所有項目。這是因爲instance('items-model')已經指向實例的根元素,所以instance('items-model')指向Items元素。

第二,次要的事情:你可能不希望在重複appearance="xxforms:internal"。這是一個擴展,用於告訴XForms引擎不要爲給定的XForms控件生成HTML標記。它不支持xforms:repeat,但最好還是用也無妨雜亂的代碼。

第三件事,也是輕微的:你可能並不需要type="xs:string"註釋,由默認值被視爲字符串。

最後,我不會用與-model的情況下結束的ID。我會用-instance代替。另一個小事情,但它可能有點混亂。所以我們把它們稱爲'main-instance'和'items-instance'。

這就是說,關鍵是寫XPath表達式來過濾的項目。現在有一個問題是你的綁定指向所有項目。因此,如果您使用bind屬性來引用您的綁定,那麼該屬性就是通過id綁定的,您無法過濾。

一種解決方案是使用Orbeon擴展功能xxf:bind()它允許你指結合從XPath表達式:

xxf:bind('items-bind')[instance('main-instance')/value = 'true' or status = 'Show'] 

你重複就變成了:

<xf:repeat ref="xxf:bind('items-bind')[instance('main-instance')/value = 'true' or status = 'Show']"> 

下面是一個完整的例子,作品:

<xh:html xmlns:xh="http://www.w3.org/1999/xhtml" 
     xmlns:xf="http://www.w3.org/2002/xforms" 
     xmlns:xxf="http://orbeon.org/oxf/xml/xforms" 
     xmlns:ev="http://www.w3.org/2001/xml-events" 
     xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xh:head> 
     <xf:model> 
      <xf:instance id="main-instance"> 
       <data> 
        <value>true</value> 
       </data> 
      </xf:instance> 
      <xf:instance id="items-instance"> 
       <Items> 
        <Item> 
         <value>1</value> 
         <status>Show</status> 
        </Item> 
        <Item> 
         <value>2</value> 
         <status>Show</status> 
        </Item> 
        <Item> 
         <value>3</value> 
         <status>Hide</status> 
        </Item> 
       </Items> 
      </xf:instance> 
      <xf:bind id="items-bind" nodeset="instance('items-instance')/Item"/> 
     </xf:model> 
    </xh:head> 
    <xh:body> 
     <xf:select ref="instance('main-instance')/value" appearance="full"> 
      <xf:item> 
       <xf:label>Include all</xf:label> 
       <xf:value>true</xf:value> 
      </xf:item> 
     </xf:select> 
     <xf:repeat ref="xxf:bind('items-bind')[instance('main-instance')/value = 'true' or status = 'Show']"> 
      <xh:div> 
       <xf:output value="concat('Value: ', value, ', status: ', status)"/> 
      </xh:div> 
     </xf:repeat> 
    </xh:body> 
</xh:html> 
+0

工程就像一個絕對的魅力!感謝您的非常詳細的反饋,非常感謝。 – Faithypop

相關問題