XSLT 1.0 中带前导零的填充数字 [英] Padding number with leading zeros in XSLT 1.0

查看:46
本文介绍了XSLT 1.0 中带前导零的填充数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在 XML 中有一个数字,它可以在一个大的 XML 文件中最多 3 位数字,必须转换为固定长度的文本才能加载到另一个系统中.

We have a number in XML that can go up to 3 digits in a large XML file that has to be converted to fixed length text for loading into another system.

我需要在输出中用前导零填充长度为 15(这是固定长度的文本)

I need to pad this with leading zeros to a length of 15 in the output (which is fixed length text)

示例:

 - 1 becomes   000000000000001
 - 11 becomes  000000000000011
 - 250 becomes 000000000000250

我试过了:

<xsl:value-of select="substring(concat('000000000000000', msg:BankAccount/msg:Counter), 12, 15)"/>

在开头获取 15 个零并取子字符串,但我一定对子字符串犯了错误,因为在结果中我得到了

to get the 15 zeros at the beginning and take the substring but I must have made a mistake with the substring because in the results I get

0000000000000000000000009LLOYDS BANK PLC
00000000000000000000000010LLOYDS BANK PLC

我也试过 format-number 但它返回 NaN

I also tried format-number but I it returns NaN

<xsl:value-of select="format-number(msg:BankAccount/msg:Counter, '000000000000000')"/>

返回'NaN'

那么我做错了什么,最好的方法是什么?

so what have I done wrong and what is the best way to do this?

推荐答案

我需要在输出中用前导零填充长度为 15 (

I need to pad this with leading zeros to a length of 15 in the output (

那就是

substring(
  concat('000000000000000', msg:BankAccount/msg:Counter), 
  string-length(msg:BankAccount/msg:Counter) + 1, 
  15
)

这篇关于XSLT 1.0 中带前导零的填充数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆