Calculate a value

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

Calculate a value

JohnBampton
This post was updated on .
Calculate a value


<xforms:instance id="data-template">
     <DOCUMENT>           

 </DOCUMENT>
 </xforms:instance>

<xforms:instance>
<LINEITEM> 
                   
                     <NOOFPACKS></NOOFPACKS> 
                    <UNITPRICE></UNITPRICE> 
                    <LINEVALUE></LINEVALUE> 
                </LINEITEM> 
</xforms:instance>

I am inserting the second instance into the first one.

How do i make linevalue equal to (noofpacks multiplied by unitprice)?
Reply | Threaded
Open this post in threaded view
|

Re: Calculate a value

Alexander Žaťko
http://www.w3.org/TR/xforms11/#model-prop-calculate


On Aug 27, 2009, at 1:03 PM, JohnBampton wrote:

>
> Calculate a value
>
>
> <xforms:instance id="data-template">
>     <DOCUMENT>          
> <LINEITEM>
>
>                     <NOOFPACKS></NOOFPACKS>
>                    <UNITPRICE></UNITPRICE>
>                    <LINEVALUE></LINEVALUE>
>                </LINEITEM>
> </DOCUMENT>
>            </xforms:instance>
>
> How do i make linevalue equal to (noofpacks multiplied by unitprice)?
> --  
> View this message in context: http://www.nabble.com/Calculate-a-value-tp25167523p25167523.html
> Sent from the ObjectWeb OPS - Users mailing list archive at  
> Nabble.com.
>
>
> --
> You receive this message as a subscriber of the [hidden email]  
> mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Calculate a value

JohnBampton
In reply to this post by JohnBampton
Hi all,

The second instance is being inserted into the first via a repeating region with a trigger.  I cannot seem to work out how to calculate the value of Linevalue, which should be unitprice * noofpacks. Any ideas?

Regards,

John.


JohnBampton wrote
Calculate a value


<xforms:instance id="data-template">
     <DOCUMENT>           

 </DOCUMENT>
 </xforms:instance>


<xforms:instance>
<LINEITEM> 
                   
                     <NOOFPACKS></NOOFPACKS> 
                    <UNITPRICE></UNITPRICE> 
                    <LINEVALUE></LINEVALUE> 
                </LINEITEM> 
</xforms:instance>

I am inserting the second instance into the first one.

How do i make linevalue equal to (noofpacks multiplied by unitprice)?
Reply | Threaded
Open this post in threaded view
|

Re: Calculate a value

Alessandro Vernet
Administrator
John,

JohnBampton wrote
The second instance is being inserted into the first via a repeating region with a trigger.  I cannot seem to work out how to calculate the value of Linevalue, which should be unitprice * noofpacks. Any ideas?
It will be easier for us to help if you attach a simple/minimal example that runs in the XForms sandbox and that tries to do what you want, but for some reason doesn't work. We can then take your example and update it to make it work.

Alex
Reply | Threaded
Open this post in threaded view
|

Re: Calculate a value

JohnBampton
Here is the example:


         
<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> 
                    </DOCUMENT>
               </data>
            </xforms:instance>
            <xforms:instance id="data-template">
                <LINEITEM> 
                    <NOOFPACKS></NOOFPACKS> 
                     <UNITPRICE></UNITPRICE> 
                    <LINEVALUE></LINEVALUE> 
                </LINEITEM> 
            </xforms:instance>
        </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>
                        </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:table>   
        </xhtml:div>     
                </xhtml:div>
        </xhtml:body>
</xhtml:html>





Regards,

John.





Alessandro Vernet wrote
John,

JohnBampton wrote
The second instance is being inserted into the first via a repeating region with a trigger.  I cannot seem to work out how to calculate the value of Linevalue, which should be unitprice * noofpacks. Any ideas?
It will be easier for us to help if you attach a simple/minimal example that runs in the XForms sandbox and that tries to do what you want, but for some reason doesn't work. We can then take your example and update it to make it work.

Alex
Reply | Threaded
Open this post in threaded view
|

Re: Calculate a value

Alessandro Vernet
Administrator
John,

JohnBampton wrote
Here is the example: [...]
The following bind does the trick:

<xforms:bind nodeset="/data/DOCUMENT/LINEITEM/LINEVALUE" calculate="if (../NOOFPACKS castable as xs:decimal and ../UNITPRICE castable as xs:decimal) then ../NOOFPACKS * ../UNITPRICE else ''"/>

I put the fill code with this change on: http://pastie.org/598087.

Alex
Reply | Threaded
Open this post in threaded view
|

Re: Calculate a value

JohnBampton
Hi Alessandro,

that works, I really appreciate the help.

Regards,

John.


Alessandro Vernet wrote
John,

JohnBampton wrote
Here is the example: [...]
The following bind does the trick:

<xforms:bind nodeset="/data/DOCUMENT/LINEITEM/LINEVALUE" calculate="if (../NOOFPACKS castable as xs:decimal and ../UNITPRICE castable as xs:decimal) then ../NOOFPACKS * ../UNITPRICE else ''"/>

I put the fill code with this change on: http://pastie.org/598087.

Alex
Reply | Threaded
Open this post in threaded view
|

Re: Calculate a value

Alessandro Vernet
Administrator
John,

JohnBampton wrote
that works, I really appreciate the help.
I am glad this helped, and you're welcome!

Alex