2012-10-12 18 views
1

我正在Orbeon表單構建器中開發一個eform。在這裏我使用中繼器(新的重複)控制。在該控件中有許多行文本控件。我想用用戶在這些控件中插入的值進行一些計算。假設兩欄有「項目數量」和「統一價格」。其中有很多行,即用戶將動態插入值。在新的重複控件中的文本控件中的計算

在這個中繼器控件的旁邊是一個文本控件,其中總量必須顯示而沒有任何按鈕事件。

E.g.假設轉發器結構,其像一個表:

column name(Number of items---unit price) 
first value(1 ----100) 
second value(5----200) 

總量必須在文本控制爲1100格的數量可以根據用戶增加被顯示(在這裏它是2)。

+0

您是使用Form Builder創建窗體還是通過「手動」編寫XForms?如果是後者,我假設你正在使用4.0里程碑版本,對吧? (在3.9中,表單生成器不支持重複)。 – avernet

回答

0

要找出總成本,我不能拿出正常的計算技巧。所以我使用了一個非常小的XQuery來解決這個問題。

我不知道你是否使用表單構建器或Xforms編碼「手工」,但我開發使用「手工」。下面是可以在Orbeon Xforms沙盒上運行的完整Xforms代碼。

<xhtml:html xmlns:xforms="http://www.w3.org/2002/xforms" 
    xmlns:f="http://orbeon.org/oxf/xml/formatting" 
    xmlns:xhtml="http://www.w3.org/1999/xhtml" 
    xmlns:xxforms="http://orbeon.org/oxf/xml/xforms" 
    xmlns:ev="http://www.w3.org/2001/xml-events" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    > 

    <xhtml:head> 

     <xforms:model xmlns:xforms="http://www.w3.org/2002/xforms" 
       xmlns:xs="http://www.w3.org/2001/XMLSchema" id="main-model"> 

      <xforms:instance id="form-instance"> 
      <form> 
       <sale> 
        <number-of-units>1</number-of-units> 
        <unit-price>100</unit-price> 
       </sale> 
       <sale> 
        <number-of-units>2</number-of-units> 
        <unit-price>500</unit-price> 
       </sale> 
      </form> 
      </xforms:instance> 


     </xforms:model> 
    </xhtml:head> 

    <xhtml:body> 

     <table> 
     <tr> 
      <td> 
       Total price: 
      </td> 
      <td> 
       <xforms:output value="sum(
             for $i in instance('form-instance')/sale 
              return $i/number-of-units * $i/unit-price 
             ) 
             " /> 
      </td> 
     </tr> 
     </table> 

    </xhtml:body> 
</xhtml:html> 

瀏覽器輸出:

enter image description here

如果您正在使用表單生成器的情況下,你可以拿起結果表達式,如果你想使用綁定定義的計算屬性。

表達:

sum(
    for $i in instance('form-instance')/sale 
     return $i/number-of-units * $i/unit-price 
    )           

祝您好運!