File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes XSL mod Operation gives wrong result due to large value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSL mod Operation gives wrong result due to large value" Watch "XSL mod Operation gives wrong result due to large value" New topic
Author

XSL mod Operation gives wrong result due to large value

Dhaval Hansaliya
Greenhorn

Joined: Sep 14, 2009
Posts: 8
Hi Friends,

I want to perform modulus operation on the XSL variable having value, more than XSD:unsignedLong datatype. (For Eg: 2100041810000023014509 mod 97)
My current implementation is:



But, <result> tag displays wrong result.
According to me, the wrong result is due to the large value.

Is there any other way to perform mod operation in XSL?

Thanks In Advance,
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

You omitted to say what the answer was according to you and what the answer was according to XSLT and why you were right and XSLT was wrong.
Dhaval Hansaliya
Greenhorn

Joined: Sep 14, 2009
Posts: 8
Hi Paul,

Thanks for replay...

Actual result for the mod operation of 2100041810000023014509 digit (2100041810000023014509 mod 97) = 32
But, when i assign this value to variable (Lets say sum) and perform same operation ($sum mod 97), i am getting the result = 86
This wrong output is because of modulo operation on the integer number, which is larger than the data type range.

Now, I have written templates in XSL file which divides the input number in small segments and perform modulo operations on each segments.


Still, update me, if there is an easier method available in the XSL to perform same operation.

thanks,
-Dhaval
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

Yes, I get 32 from my Windows calculator too.

I didn't want to say that XSLT was "wrong" to come up with something else because I remember some complaints from way back when XSLT was first designed. My recollection was that people who tried to write transformers in a language other than Java claimed they were at a disadvantage because the spec said (essentially) that XSLT had to do arithmetic exactly as Java did it.

But now I can't find any evidence of that on the web. However, I'm pretty sure your theory about why XSLT gets the wrong answer for that calculation is right. Unfortunately I don't have any advice for you about how to get the right answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XSL mod Operation gives wrong result due to large value