How to add a conditional attribute for a sum

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

How to add a conditional attribute for a sum

Kannan Ekanath
Hi,
I have a repeat set where I have some amount and in the bottom I want to display the total amount. I have said something like,
<xf:output class="twms-total-value"
                 value="format-number(sum(/laborDetail/hoursSpent), '#.00')">
</xf:output>

However it is possible that some hours spent mite be empty, in which case I want to substitute 0 for empty while calculation. I tried something like,

format-number( sum(if(number(/taskView/claim/serviceInformation/serviceDetail/laborPerformed/laborDetail/hoursSpent), '#.00')

However this thing errors out saying that in a repeat row I should not use the number() function. Can someone tell me how this can be achieved?
--
Regards,
Kannan Ekanath

--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

RE: How to add a conditional attribute for a sum

Ryan Puddephatt
Kannan
    Try if(sum(/path/to/number) gt 0) then format-number(sum(/path/to/number),'#.00') else ''
Ryan

Ryan Puddephatt
Software Engineer
 

Teleflex Group - IT UK
1 Michaelson Square
Livingston
West Lothian
Scotland
EH54 7DP
 
e> [hidden email]
t> +44(0)1506 407 110
f> +44(0)1506 407 108
w> www.teleflex.com

 


From: [hidden email] [mailto:[hidden email]]
Sent: 08 January 2007 07:34
To: [hidden email]
Subject: [ops-users] How to add a conditional attribute for a sum

Hi,
I have a repeat set where I have some amount and in the bottom I want to display the total amount. I have said something like,
<xf:output class="twms-total-value"
                 value="format-number(sum(/laborDetail/hoursSpent), '#.00')">
</xf:output>

However it is possible that some hours spent mite be empty, in which case I want to substitute 0 for empty while calculation. I tried something like,

format-number( sum(if(number(/taskView/claim/serviceInformation/serviceDetail/laborPerformed/laborDetail/hoursSpent), '#.00')

However this thing errors out saying that in a repeat row I should not use the number() function. Can someone tell me how this can be achieved?
--
Regards,
Kannan Ekanath


--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: How to add a conditional attribute for a sum

Kannan Ekanath
Ryan,
The suggestion of if(sum(/path/to/number) gt 0) then format-number(sum(/path/to/number),'#.00') doesnt work for me because the sum(/path/to/number) itself throws an error because the value is an empty "". The following error is thrown in the browser (If I use tools like firebug etc in firefox)
<message>oxf:/ops/xforms/xforms-server.xpl, line 44, column 44, description executing processor: oxf:/ops/xforms/xforms-server.xpl, line 38, column 95, description reading processor output: null, line -1, column -1: Cannot convert string "" to a double

Cannot convert string "" to a double
null, line -1, column -1: Cannot convert string "" to a double
Cannot convert string "" to a double
oxf:/ops/xforms/xforms-server.xpl, line 38, column 95, description reading processor output: null, line -1, column -1: Cannot convert string "" to a double
Cannot convert string "" to a double
null, line -1, column -1: Cannot convert string "" to a double
Cannot convert string "" to a double</message>

Note that sum is failing and not the format,  Do you have any suggestions for this?

Regards,
Kannan
On 1/8/07, Ryan Puddephatt <[hidden email]> wrote:
Kannan
    Try if(sum(/path/to/number) gt 0) then format-number(sum(/path/to/number),'#.00') else ''
Ryan

Ryan Puddephatt
Software Engineer
 

Teleflex Group - IT UK
1 Michaelson Square
Livingston
West Lothian
Scotland
EH54 7DP
 
e> [hidden email]
t> +44(0)1506 407 110
f> +44(0)1506 407 108
w> <a href="http://www.teleflex.com/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">www.teleflex.com

 


From: [hidden email] [mailto:[hidden email]]
Sent: 08 January 2007 07:34
To: [hidden email]
Subject: [ops-users] How to add a conditional attribute for a sum

Hi,
I have a repeat set where I have some amount and in the bottom I want to display the total amount. I have said something like,
<xf:output class="twms-total-value"
                 value="format-number(sum(/laborDetail/hoursSpent), '#.00')">
</xf:output>

However it is possible that some hours spent mite be empty, in which case I want to substitute 0 for empty while calculation. I tried something like,

format-number( sum(if(number(/taskView/claim/serviceInformation/serviceDetail/laborPerformed/laborDetail/hoursSpent), '#.00')

However this thing errors out saying that in a repeat row I should not use the number() function. Can someone tell me how this can be achieved?
--
Regards,
Kannan Ekanath




--
Regards,
Kannan Ekanath

--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

RE: How to add a conditional attribute for a sum

Ryan Puddephatt
add "not(empty(/path/to/number)) and" to the if
 

Ryan Puddephatt
Software Engineer
 

Teleflex Group - IT UK
1 Michaelson Square
Livingston
West Lothian
Scotland
EH54 7DP
 
e> [hidden email]
t> +44(0)1506 407 110
f> +44(0)1506 407 108
w> www.teleflex.com

 


From: [hidden email] [mailto:[hidden email]]
Sent: 08 January 2007 11:43
To: [hidden email]
Subject: Re: [ops-users] How to add a conditional attribute for a sum

Ryan,
The suggestion of if(sum(/path/to/number) gt 0) then format-number(sum(/path/to/number),'#.00') doesnt work for me because the sum(/path/to/number) itself throws an error because the value is an empty "". The following error is thrown in the browser (If I use tools like firebug etc in firefox)
<message>oxf:/ops/xforms/xforms-server.xpl, line 44, column 44, description executing processor: oxf:/ops/xforms/xforms-server.xpl, line 38, column 95, description reading processor output: null, line -1, column -1: Cannot convert string "" to a double

Cannot convert string "" to a double
null, line -1, column -1: Cannot convert string "" to a double
Cannot convert string "" to a double
oxf:/ops/xforms/xforms-server.xpl, line 38, column 95, description reading processor output: null, line -1, column -1: Cannot convert string "" to a double
Cannot convert string "" to a double
null, line -1, column -1: Cannot convert string "" to a double
Cannot convert string "" to a double</message>

Note that sum is failing and not the format,  Do you have any suggestions for this?

Regards,
Kannan
On 1/8/07, Ryan Puddephatt <[hidden email]> wrote:
Kannan
    Try if(sum(/path/to/number) gt 0) then format-number(sum(/path/to/number),'#.00') else ''
Ryan

Ryan Puddephatt
Software Engineer
 

Teleflex Group - IT UK
1 Michaelson Square
Livingston
West Lothian
Scotland
EH54 7DP
 
e> [hidden email]
t> +44(0)1506 407 110
f> +44(0)1506 407 108
w> <A onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.teleflex.com/" target=_blank>www.teleflex.com

 


From: [hidden email] [mailto:[hidden email]]
Sent: 08 January 2007 07:34
To: [hidden email]
Subject: [ops-users] How to add a conditional attribute for a sum

Hi,
I have a repeat set where I have some amount and in the bottom I want to display the total amount. I have said something like,
<xf:output class="twms-total-value"
                 value="format-number(sum(/laborDetail/hoursSpent), '#.00')">
</xf:output>

However it is possible that some hours spent mite be empty, in which case I want to substitute 0 for empty while calculation. I tried something like,

format-number( sum(if(number(/taskView/claim/serviceInformation/serviceDetail/laborPerformed/laborDetail/hoursSpent), '#.00')

However this thing errors out saying that in a repeat row I should not use the number() function. Can someone tell me how this can be achieved?
--
Regards,
Kannan Ekanath




--
Regards,
Kannan Ekanath


--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: How to add a conditional attribute for a sum

Kannan Ekanath
Ryan,
Apologies If I am not doing it right.

Even with that the issue will still exist. Adding not(empty doesnt do the trick). To show you what I exactly want, take the file that I have attached with this email. This has some menu order items. Just clear some price in some row, you will see the error that I had mentioned.

On 1/8/07, Ryan Puddephatt <[hidden email]> wrote:
add "not(empty(/path/to/number)) and" to the if
 

Ryan Puddephatt
Software Engineer
 

Teleflex Group - IT UK
1 Michaelson Square
Livingston
West Lothian
Scotland
EH54 7DP
 
e> [hidden email]
t> +44(0)1506 407 110
f> +44(0)1506 407 108
w> <a href="http://www.teleflex.com/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">www.teleflex.com

 


From: [hidden email] [mailto:[hidden email]]
Sent: 08 January 2007 11:43
To: [hidden email]
Subject: Re: [ops-users] How to add a conditional attribute for a sum

Ryan,
The suggestion of if(sum(/path/to/number) gt 0) then format-number(sum(/path/to/number),'#.00') doesnt work for me because the sum(/path/to/number) itself throws an error because the value is an empty "". The following error is thrown in the browser (If I use tools like firebug etc in firefox)
<message>oxf:/ops/xforms/xforms-server.xpl, line 44, column 44, description executing processor: oxf:/ops/xforms/xforms-server.xpl, line 38, column 95, description reading processor output: null, line -1, column -1: Cannot convert string "" to a double


Cannot convert string "" to a double
null, line -1, column -1: Cannot convert string "" to a double
Cannot convert string "" to a double
oxf:/ops/xforms/xforms-server.xpl, line 38, column 95, description reading processor output: null, line -1, column -1: Cannot convert string "" to a double

Cannot convert string "" to a double
null, line -1, column -1: Cannot convert string "" to a double
Cannot convert string "" to a double</message>

Note that sum is failing and not the format,  Do you have any suggestions for this?

Regards,
Kannan
On 1/8/07, Ryan Puddephatt <[hidden email]> wrote:
Kannan
    Try if(sum(/path/to/number) gt 0) then format-number(sum(/path/to/number),'#.00') else ''
Ryan

Ryan Puddephatt
Software Engineer
 

Teleflex Group - IT UK
1 Michaelson Square
Livingston
West Lothian
Scotland
EH54 7DP
 
e> [hidden email]
t> +44(0)1506 407 110
f> +44(0)1506 407 108
w> <a href="http://www.teleflex.com/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">www.teleflex.com

 


From: [hidden email] [mailto:[hidden email]]
Sent: 08 January 2007 07:34
To: [hidden email]
Subject: [ops-users] How to add a conditional attribute for a sum

Hi,
I have a repeat set where I have some amount and in the bottom I want to display the total amount. I have said something like,
<xf:output class="twms-total-value"
                 value="format-number(sum(/laborDetail/hoursSpent), '#.00')">
</xf:output>

However it is possible that some hours spent mite be empty, in which case I want to substitute 0 for empty while calculation. I tried something like,

format-number( sum(if(number(/taskView/claim/serviceInformation/serviceDetail/laborPerformed/laborDetail/hoursSpent), '#.00')

However this thing errors out saying that in a repeat row I should not use the number() function. Can someone tell me how this can be achieved?
--
Regards,
Kannan Ekanath




--
Regards,
Kannan Ekanath




--
Regards,
Kannan Ekanath

--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws

Summation.xhtml (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to add a conditional attribute for a sum

Erik Bruchez
Administrator
In reply to this post by Kannan Ekanath
Kannan,

Try something along this line:

sum(for $hour in /laborDetail/hoursSpent return if ($hour = '') then 0
else $hour)

-Erik

[hidden email] wrote:

> Hi,
> I have a repeat set where I have some amount and in the bottom I want to
> display the total amount. I have said something like,
> <xf:output class="twms-total-value"
>                  value="format-number(sum(/laborDetail/hoursSpent),
> '#.00')">
> </xf:output>
>
> However it is possible that some hours spent mite be empty, in which
> case I want to substitute 0 for empty while calculation. I tried
> something like,
>
> format-number(
> sum(if(number(/taskView/claim/serviceInformation/serviceDetail/laborPerformed/laborDetail/hoursSpent),
> '#.00')
>
> However this thing errors out saying that in a repeat row I should not
> use the number() function. Can someone tell me how this can be achieved?
> --
> Regards,
> Kannan Ekanath
>
>
> ------------------------------------------------------------------------
>
>
> --
> 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
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws

--
Orbeon Forms - Web Forms for the Enterprise Done the Right Way
http://www.orbeon.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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: How to add a conditional attribute for a sum

Kannan Ekanath
Thanks Erik,
It worked :)

Regards,
Kannan


--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: How to add a conditional attribute for a sum

Alessandro  Vernet
Administrator
Wouldn't:

sum(/laborDetail/hoursSpent[. != ''])

also work?

Alex

On 1/9/07, [hidden email] <[hidden email]> wrote:

> Thanks Erik,
> It worked :)
>
> Regards,
> Kannan
>
>
> --
> 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
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
>
>
>

--
Blog (XML, Web apps, Open Source):
http://www.orbeon.com/blog/



--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: How to add a conditional attribute for a sum

Kannan Ekanath
This seems to be a better way :) It works !!!

Regards,
Kannan


--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: How to add a conditional attribute for a sum

bsteuhl
what about when a user accidentally enters a string character?  An error is thrown on the calculation even if there is a bind on the nodeset of type="xs:decimal".  How do you prevent a calculation from running if there is an error?  I have attempted to do a count of fr-errors-instance/error and if != 0 do not run but this does not work.  Any suggestions - what am I missing.  Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: How to add a conditional attribute for a sum

bsteuhl
Never mind I figured it out - set an xforms:output using value attribute with a conditional test to see if the sum is 'castable as xs:integer'.  If it is castable, perform calculation, string appears as error on xform.  Thanks.