XSLT mod 检查大数
我正在尝试在 XSLT 1.0 中对 17 位数字进行模数 11 检查。然而,它似乎总是给出错误的输出。
我能找到的关于此的唯一信息位于
我过去曾使用 Luhn 检查器的 XSLT 模板,我意识到这与模数检查的工作方式不同,但我想知道是否有人知道可以计算大数模数的 XSLT 模板?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一个纯 XSLT 1.0 解决方案,可以计算任意大小的整数
$n
的$n mod 11
:应用此转换时在以下 XML 文档上:
生成所需的正确结果 (
12345678901234567 mod 11
):请注意:
这个解决方案可以很容易地推广到计算任何整数
$m
的$n mod $m
——只需将$m
作为第二个参数。另一个概括是作为参数传递限制,超过该限制就无法使用
mod
运算符直接计算$n mod $m
。当使用 XSLT 2.0 并将$n
作为xs:integer
或xs:decimal
时,这可能很有用。另一种替代方法是使用 Saxon.NET XSLT 2.0 处理器或任何其他实现大整数算术的 XSLT 2.0 处理器。那么解决方案就是使用
mod
运算符:....
当此转换与 Saxon 9.1.07 应用于同一个 XML 文档(如上)时,会产生相同的正确结果:
There is a pure XSLT 1.0 solution which calculates
$n mod 11
for integer$n
of 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 $m
for any integer$m
-- just pass$m
as a second parameter.Another generalization is to pass as parameter the limit above which
$n mod $m
cannot be calculated directly using themod
operator. This can be useful when using XSLT 2.0 and having$n
as eitherxs:integer
orxs: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
mod
operator:....
When this transformation is applied with Saxon 9.1.07 on the same XML document (above), the same correct result is produced:
这是因为在 MSXML 中,数字类型相当于 .NET
Double
数据类型,其精度为 15-16 位。尝试这个示例:
输出:
我认为您可以使用 C# 或 JScript 扩展 XSLT,因为 MSXML 支持此功能。
参考: http://msdn.microsoft.com/ en-us/library/533texsx(v=VS.100).aspx, http://msdn.microsoft.com/en-us/magazine/cc302079.aspx
That is because in MSXML number type is equivalent of .NET
Double
datatype, which has precision of 15-16 digits.Try this sample:
Output:
I think you can extend XSLT with C# or JScript, because MSXML supports this.
Reference: http://msdn.microsoft.com/en-us/library/533texsx(v=VS.100).aspx, http://msdn.microsoft.com/en-us/magazine/cc302079.aspx