Auto increment a value in repeating region

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Auto increment a value in repeating region

JohnBampton
Hi all,  I want an autoincrement field in my repeating region.  Code is below.  it should be the field "lineno"

Does anyone know how to do this?

Regards,

John.
         
<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:xi="http://www.w3.org/2001/XInclude"
        xmlns:xxi="http://orbeon.org/oxf/xml/xinclude" xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:widget="http://orbeon.org/oxf/xml/widget" xmlns:ev="http://www.w3.org/2001/xml-events"
        xmlns:xdt="http://www.w3.org/2005/xpath-datatypes" xmlns:xbl="http://www.w3.org/ns/xbl"
        xmlns:fr="http://orbeon.org/oxf/xml/form-runner" lang="en">
        <xhtml:head>
        <xforms:model id="main-model"> 
             <xforms:instance id="data-instance">
              <data>
                <DOCUMENT> 
                    <TOTALS>
                            <GOODSTOTAL></GOODSTOTAL>
                        </TOTALS> 
                    </DOCUMENT>
               </data>
            </xforms:instance>
            <xforms:instance id="data-template">
                <LINEITEM> 
                     <LINENO></LINENO> 
                     <NOOFPACKS></NOOFPACKS> 
                     <UNITPRICE></UNITPRICE> 
                    <LINEVALUE></LINEVALUE> 
                </LINEITEM> 
            </xforms:instance>
            <xforms:bind nodeset="/data/DOCUMENT/LINEITEM/LINEVALUE" calculate="if (../NOOFPACKS castable as xs:decimal and ../UNITPRICE castable as
xs:decimal) then ../NOOFPACKS * ../UNITPRICE else ''"/>
            <xforms:bind nodeset="/data/DOCUMENT/TOTALS/GOODSTOTAL" calculate="if (sum(/data/DOCUMENT/LINEITEM/LINEVALUE) castable as xs:decimal) then sum(/data/DOCUMENT/LINEITEM/LINEVALUE) else ''"/>
        </xforms:model>
        </xhtml:head>
        <xhtml:body>
                <xhtml:div id="borderwrap">
        <xhtml:div>
            <xhtml:table width="1000px">
            <xhtml:tr>
                    <xhtml:td colspan="7">
                         <xforms:trigger appearance="minimal">
                                <xforms:label>Add additional line</xforms:label>
                                  <xforms:insert ev:event="DOMActivate" context="instance('data-instance')/DOCUMENT" nodeset="DOCUMENT/LINEITEM"
                                at="1" position="before" origin="instance('data-template')"/>
                            </xforms:trigger>
                        <xhtml:br/>
                        <xhtml:br/>
                    </xhtml:td>
                </xhtml:tr>
                <xforms:repeat nodeset="DOCUMENT/LINEITEM" id="al-repeat">
                    <xhtml:tr>
                    <xhtml:td colspan="7">
                           <xforms:trigger appearance="minimal">
                            <xforms:delete ev:event="DOMActivate" context="instance('data-instance')" nodeset="DOCUMENT/LINEITEM"
                                           at="index('al-repeat')"/>
                            <xforms:label>Delete</xforms:label>
                        </xforms:trigger>
                        </xhtml:td>
                     </xhtml:tr>
                     <xhtml:tr valign="top"> 
                      <xhtml:td>
                        <xforms:input id="lineno" ref="LINENO" incremental="true" style="display:none;" class="input">
                    </xforms:input>
                        </xhtml:td> 
                        <xhtml:td>
                        <xforms:input id="noofpacks" ref="NOOFPACKS" incremental="true" class="input">
                                <xforms:label>noofpacks</xforms:label>
                    </xforms:input>
                        </xhtml:td>
                         <xhtml:td>
                            <xforms:input id="unitprice" ref="UNITPRICE" incremental="true" class="input"> 
                                 <xforms:label>UNITPRICE</xforms:label>
                    </xforms:input>
                        </xhtml:td>
                          <xhtml:td>
                            <xforms:input id="linetotal" ref="LINEVALUE"  incremental="true">
                             <xforms:label>LINEVALUE</xforms:label>
                            </xforms:input>
                        </xhtml:td>
                    </xhtml:tr>
            </xforms:repeat>
                <xhtml:tr>
                    <xhtml:td colspan="4"  style="text-align:right">
                          <xforms:input id="totalvalue" ref="DOCUMENT/TOTALS/GOODSTOTAL"  incremental="true">
                             <xforms:label>Total Value (GBP):</xforms:label></xforms:input>
                    </xhtml:td>
                </xhtml:tr>
             </xhtml:table>   
        </xhtml:div>     
                </xhtml:div>
        </xhtml:body>
</xhtml:html>
Reply | Threaded
Open this post in threaded view
|

Re: Auto increment a value in repeating region

JohnBampton
would it be = 1 + count(preceding::LINENO)  in a bind calculate statement?

JohnBampton wrote
Hi all,  I want an autoincrement field in my repeating region.  Code is below.  it should be the field "lineno"

Does anyone know how to do this?

Regards,

John.
         
<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:xi="http://www.w3.org/2001/XInclude"
        xmlns:xxi="http://orbeon.org/oxf/xml/xinclude" xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:widget="http://orbeon.org/oxf/xml/widget" xmlns:ev="http://www.w3.org/2001/xml-events"
        xmlns:xdt="http://www.w3.org/2005/xpath-datatypes" xmlns:xbl="http://www.w3.org/ns/xbl"
        xmlns:fr="http://orbeon.org/oxf/xml/form-runner" lang="en">
        <xhtml:head>
        <xforms:model id="main-model"> 
             <xforms:instance id="data-instance">
              <data>
                <DOCUMENT> 
                    <TOTALS>
                            <GOODSTOTAL></GOODSTOTAL>
                        </TOTALS> 
                    </DOCUMENT>
               </data>
            </xforms:instance>
            <xforms:instance id="data-template">
                <LINEITEM> 
                     <LINENO></LINENO> 
                     <NOOFPACKS></NOOFPACKS> 
                     <UNITPRICE></UNITPRICE> 
                    <LINEVALUE></LINEVALUE> 
                </LINEITEM> 
            </xforms:instance>
            <xforms:bind nodeset="/data/DOCUMENT/LINEITEM/LINEVALUE" calculate="if (../NOOFPACKS castable as xs:decimal and ../UNITPRICE castable as
xs:decimal) then ../NOOFPACKS * ../UNITPRICE else ''"/>
            <xforms:bind nodeset="/data/DOCUMENT/TOTALS/GOODSTOTAL" calculate="if (sum(/data/DOCUMENT/LINEITEM/LINEVALUE) castable as xs:decimal) then sum(/data/DOCUMENT/LINEITEM/LINEVALUE) else ''"/>
        </xforms:model>
        </xhtml:head>
        <xhtml:body>
                <xhtml:div id="borderwrap">
        <xhtml:div>
            <xhtml:table width="1000px">
            <xhtml:tr>
                    <xhtml:td colspan="7">
                         <xforms:trigger appearance="minimal">
                                <xforms:label>Add additional line</xforms:label>
                                  <xforms:insert ev:event="DOMActivate" context="instance('data-instance')/DOCUMENT" nodeset="DOCUMENT/LINEITEM"
                                at="1" position="before" origin="instance('data-template')"/>
                            </xforms:trigger>
                        <xhtml:br/>
                        <xhtml:br/>
                    </xhtml:td>
                </xhtml:tr>
                <xforms:repeat nodeset="DOCUMENT/LINEITEM" id="al-repeat">
                    <xhtml:tr>
                    <xhtml:td colspan="7">
                           <xforms:trigger appearance="minimal">
                            <xforms:delete ev:event="DOMActivate" context="instance('data-instance')" nodeset="DOCUMENT/LINEITEM"
                                           at="index('al-repeat')"/>
                            <xforms:label>Delete</xforms:label>
                        </xforms:trigger>
                        </xhtml:td>
                     </xhtml:tr>
                     <xhtml:tr valign="top"> 
                      <xhtml:td>
                        <xforms:input id="lineno" ref="LINENO" incremental="true" style="display:none;" class="input">
                    </xforms:input>
                        </xhtml:td> 
                        <xhtml:td>
                        <xforms:input id="noofpacks" ref="NOOFPACKS" incremental="true" class="input">
                                <xforms:label>noofpacks</xforms:label>
                    </xforms:input>
                        </xhtml:td>
                         <xhtml:td>
                            <xforms:input id="unitprice" ref="UNITPRICE" incremental="true" class="input"> 
                                 <xforms:label>UNITPRICE</xforms:label>
                    </xforms:input>
                        </xhtml:td>
                          <xhtml:td>
                            <xforms:input id="linetotal" ref="LINEVALUE"  incremental="true">
                             <xforms:label>LINEVALUE</xforms:label>
                            </xforms:input>
                        </xhtml:td>
                    </xhtml:tr>
            </xforms:repeat>
                <xhtml:tr>
                    <xhtml:td colspan="4"  style="text-align:right">
                          <xforms:input id="totalvalue" ref="DOCUMENT/TOTALS/GOODSTOTAL"  incremental="true">
                             <xforms:label>Total Value (GBP):</xforms:label></xforms:input>
                    </xhtml:td>
                </xhtml:tr>
             </xhtml:table>   
        </xhtml:div>     
                </xhtml:div>
        </xhtml:body>
</xhtml:html>
Reply | Threaded
Open this post in threaded view
|

Re: Auto increment a value in repeating region

Alessandro Vernet
Administrator
John,

JohnBampton wrote
would it be = 1 + count(preceding::LINENO)  in a bind calculate statement?
Right. I prefer count(../preceding-sibling::LINEITEM) + 1 just to handle the case where you would have LINENO elements somewhere else in the document. For reference, the updated code is: http://pastie.org/599996.

Alex