2014-01-17 58 views
2

如果我有一個XForms的情況下,像的XForms:將所有列表項的子項有一個週期

<xforms:instance id="myvrs"> 
    <myvrs> 
     <subitem /> 
    </myvrs> 
</xforms:instance> 
<xforms:instance id="tmp"> 
    <temp> 
     <item><subitem>11</subitem></item> 
     <item><subitem>21</subitem><subitem>22</subitem></item> 
     <item></item> 
    </temp> 
</xforms:instance> 

如何使用週期像

<xforms:trigger> 
    <xforms:label>button</xforms:label> 
    <xforms:action events:event="DOMActivate"> 
    forall in instance('tmp')/item 
     <xforms:insert context="instance('tmp')/item" origin="instance('myvrs')/subitem" /> 
    endforall 
    </xforms:action> 
</xforms:trigger> 

我可以得到例如

<xforms:instance id="tmp"> 
    <temp> 
     <item><subitem>11</subitem><subitem></subitem></item> 
     <item><subitem>21</subitem><subitem>22</subitem><subitem></subitem></item> 
     <item><subitem></subitem></item> 
    </temp> 
</xforms:instance> 

謝謝

回答

3

要迭代在XForms 1.1中,您需要使用while屬性(請參閱10.18 Iteration of XForms Actions)。

你的情況可以用另外一個實例來完成:那麼

<xf:instance id="iterator"> 
    <iterator xmlns=""></iterator> 
</xf:instance> 

和動作可能是:

<xf:action ev:event="DOMActivate"> 
    <xf:setvalue ref="instance('iterator')" value="1"></xf:setvalue> 
    <xf:action while="instance('iterator') &lt; count(instance('tmp')/item)"> 
     <xf:insert context="instance('tmp')/item[position()=instance('iterator')]" 
      origin="instance('myvrs')/subitem" nodeset="subitem" position="after"></xf:insert> 
     <xf:setvalue ref="instance('iterator')" value="instance('iterator') + 1"></xf:setvalue> 
    </xf:action> 
</xf:action> 

注意,這是標準的XForms 1.1和應與工作其他實現。

完整的XForms是:

<html xmlns:xf="http://www.w3.org/2002/xforms" xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

    <head> 
     <title>Insert for all</title> 
     <xf:model> 
      <xf:instance id="myvrs"> 
       <myvrs xmlns=""> 
        <subitem></subitem> 
       </myvrs> 
      </xf:instance> 
      <xf:instance id="tmp"> 
       <temp xmlns=""> 
        <item> 
         <subitem>11</subitem> 
        </item> 
        <item> 
         <subitem>21</subitem> 
         <subitem>22</subitem> 
        </item> 
        <item></item> 
       </temp> 
      </xf:instance> 
      <xf:instance id="iterator"> 
       <iterator xmlns=""></iterator> 
      </xf:instance> 
     </xf:model> 
    </head> 
    <body> 
     <xf:trigger> 
      <xf:label>button</xf:label> 
      <xf:action ev:event="DOMActivate"> 
       <xf:setvalue ref="instance('iterator')" value="1"></xf:setvalue> 
       <xf:action while="instance('iterator') &lt; count(instance('tmp')/item)"> 
        <xf:insert context="instance('tmp')/item[position()=instance('iterator')]" 
         origin="instance('myvrs')/subitem" nodeset="subitem" position="after"></xf:insert> 
        <xf:setvalue ref="instance('iterator')" value="instance('iterator') + 1"></xf:setvalue> 
       </xf:action> 
      </xf:action> 
     </xf:trigger> 
     <fr:xforms-inspector xmlns:fr="http://orbeon.org/oxf/xml/form-runner"></fr:xforms-inspector> 
    </body> 
</html> 
+0

感謝YOUT這麼多! – user2301515

相關問題