Dhaval Hansaliya

Greenhorn

Posts: 8

posted 7 years ago

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,

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,

Dhaval Hansaliya

Greenhorn

Posts: 8

posted 7 years ago

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

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

posted 7 years ago

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