I’m trying to do a modulus 11 check in XSLT 1.0 for a 17 digit number. However, it always seems to give the wrong output.
The only information I’ve been able to find about this, was in this post, however, no solution was found.
I have in the past used an XSLT template for a Luhn checker, I realise that this works differently to a modulus check but I was wondering if anyone was aware of an XSLT template which can calculate moduluses of large numbers?
There is a pure XSLT 1.0 solution which calculates
$n mod 11for integer$nof any size:When this transformation is applied on the following XML document:
the wanted correct result (
12345678901234567 mod 11) is produced:Do note:
This solution can easily be generalized to calculate
$n mod $mfor any integer$m— just pass$mas a second parameter.Another generalization is to pass as parameter the limit above which
$n mod $mcannot be calculated directly using themodoperator. This can be useful when using XSLT 2.0 and having$nas eitherxs:integerorxs:decimal.Another alternative is to use the Saxon.NET XSLT 2.0 processor or any other XSLT 2.0 processor that implements Big Integer arithmetics. Then the solution is just to use the
modoperator:….
When this transformation is applied with Saxon 9.1.07 on the same XML document (above), the same correct result is produced: