Numeric comparisons?

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

Numeric comparisons?

Robin Diederen
Numeric comparisons?

Hi all,

 

I'm trying to control the behaviour of a xform trigger by evaluating some values from an XML instance like this:

 

<xforms:setvalue ref="instance('query-parameters')/parameters:page" value="if (instance('query-response')//rsp:page &lt; instance('query-response')//rsp:totalPages)......

 

This doesn't work as expected; the &lt; seems to do a lexicographic comparison of both values.

 

For example, if instance('query-response')//rsp:totalPages evaluates to 63, then (by the &lt; operator) 6 is considered less, but 7 is considered greater.

 

How can I do a proper numeric comparison?

 

Best, Robin



--
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: Numeric comparisons?

fl.schmitt(ops-users)
Hi Robin,

> <xforms:setvalue ref="instance('query-parameters')/parameters:page"
> value="if (instance('query-response')//rsp:page &lt;
> instance('query-response')//rsp:totalPages)......

> This doesn't work as expected; the &lt; seems to do a lexicographic
> comparison of both values.

> For example, if instance('query-response')//rsp:totalPages evaluates to
> 63, then (by the &lt; operator) 6 is considered less, but 7 is
> considered greater.

> How can I do a proper numeric comparison?


you could try to convert the xpath result explicitly to an numeric value
using number():

"if (number(instance('query-response')//rsp:page) lt
number(instance('query-response')//rsp:totalPages)) ..."

HTH
florian


--
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: Re: Numeric comparisons?

Robin Diederen
RE: [ops-users] Re: Numeric comparisons?

Hello Florian,

 

Thanks, that works like a charm!

 

Best, Robin
 

-----Original message-----
From: Florian Schmitt <[hidden email]>
Sent: Fri 19-02-2010 15:21
To: [hidden email];
Subject: [ops-users] Re: Numeric comparisons?

Hi Robin,

> <xforms:setvalue ref="instance('query-parameters')/parameters:page"
> value="if (instance('query-response')//rsp:page &lt;
> instance('query-response')//rsp:totalPages)......

> This doesn't work as expected; the &lt; seems to do a lexicographic
> comparison of both values.

> For example, if instance('query-response')//rsp:totalPages evaluates to
> 63, then (by the &lt; operator) 6 is considered less, but 7 is
> considered greater.

> How can I do a proper numeric comparison?


you could try to convert the xpath result explicitly to an numeric value
using number():

"if (number(instance('query-response')//rsp:page) lt
number(instance('query-response')//rsp:totalPages)) ..."

HTH
florian


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