Get XPath sum function to ignore non-numeric data

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

Get XPath sum function to ignore non-numeric data

Edpriwer
I have a form that users can input numbers (decimals) into. After the user inputs a number a total value is calculated using the sum() function:

<xforms:setvalue ref="instance('total-instance')/total" value="sum(instance('review-instance')/PerformanceObjectiveDetails/Weighting[.!=''])"/>

When the user enters a non-numeric, the following error message appears at the top of my page:
XForms error: Cannot convert string "abc" to a double

Which of course makes sense, however I'd like to know how to get my sum function to ignore any non-numeric data, so that the aforementioned exception isn't thrown. As you can see my sum() currently ignores empty strings by using [.!=''], so I'd like to have something like [.!='' and isNumeric()]. Is there a way to achieve this in xpath - I haven't been able to find it.

Alternatively, is there a non-javascript way to limit the user to only entering decimals in an xforms:input field?

Alternatively, as a last option, can I hide the 'XForms error: Cannot convert string "abc" to a double' message from the user? (The user will still be alerted that they entered an incorrect value because the Weighting field is defined as a decimal in the schema).

Any input/ideas will be appreciated, thanks!




--
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: Get XPath sum function to ignore non-numeric data

David McIntyre
Have you tried [.!='' and . castable as xs:double]?
 
Cheers,
 
    Dave Mc
 
 
Dave McIntyre   MA, DPhil
Software Developer
[hidden email]
P: +64 9 638 0600
F: +64 9 638 0699
M: +64 21 212 8087
S: dave.mcintyre


>>> <[hidden email]> 13/04/2007 3:50 p.m. >>>
I have a form that users can input numbers (decimals) into. After the user inputs a number a total value is calculated using the sum() function:

<xforms:setvalue ref="instance('total-instance')/total" value="sum(instance('review-instance')/PerformanceObjectiveDetails/Weighting[.!=''])"/>

When the user enters a non-numeric, the following error message appears at the top of my page:
XForms error: Cannot convert string "abc" to a double

Which of course makes sense, however I'd like to know how to get my sum function to ignore any non-numeric data, so that the aforementioned exception isn't thrown. As you can see my sum() currently ignores empty strings by using [.!=''], so I'd like to have something like [.!='' and isNumeric()]. Is there a way to achieve this in xpath - I haven't been able to find it.

Alternatively, is there a non-javascript way to limit the user to only entering decimals in an xforms:input field?

Alternatively, as a last option, can I hide the 'XForms error: Cannot convert string "abc" to a double' message from the user? (The user will still be alerted that they entered an incorrect value because the Weighting field is defined as a decimal in the schema).

Any input/ideas will be appreciated, thanks!




--
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: Get XPath sum function to ignore non-numeric data

Edpriwer
I have now, thanks!

David McIntyre wrote:

> Have you tried [.!='' and . castable as xs:double]?
>  
> Cheers,
>  
>     Dave Mc
>  
>  
>
> **
>
> *Dave McIntyre   *MA, DPhil
> *Software Developer*
> [hidden email] <mailto:[hidden email]>
> P: +64 9 638 0600
> F: +64 9 638 0699
> M: +64 21 212 8087
> S: dave.mcintyre
> www.orionhealth.com <http://www.orionhealth.com/>
>
>
>
> >>> <[hidden email]> 13/04/2007 3:50 p.m. >>>
> I have a form that users can input numbers (decimals) into. After the
> user inputs a number a total value is calculated using the sum() function:
>
> <xforms:setvalue ref="instance('total-instance')/total"
> value="sum(instance('review-instance')/PerformanceObjectiveDetails/Weighting[.!=''])"/>
>
> When the user enters a non-numeric, the following error message
> appears at the top of my page:
> XForms error: Cannot convert string "abc" to a double
>
> Which of course makes sense, however I'd like to know how to get my
> sum function to ignore any non-numeric data, so that the
> aforementioned exception isn't thrown. As you can see my sum()
> currently ignores empty strings by using [.!=''], so I'd like to have
> something like [.!='' and isNumeric()]. Is there a way to achieve this
> in xpath - I haven't been able to find it.
>
> Alternatively, is there a non-javascript way to limit the user to only
> entering decimals in an xforms:input field?
>
> Alternatively, as a last option, can I hide the 'XForms error: Cannot
> convert string "abc" to a double' message from the user? (The user
> will still be alerted that they entered an incorrect value because the
> Weighting field is defined as a decimal in the schema).
>
> Any input/ideas will be appreciated, thanks!
>
>
> ------------------------------------------------------------------------
>
>
> --
> 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
>  


--
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