Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml XSLT 1.0中带前导零的填充数字_Xml_Xslt 1.0_String Formatting_Msxml6 - Fatal编程技术网

Xml XSLT 1.0中带前导零的填充数字

Xml XSLT 1.0中带前导零的填充数字,xml,xslt-1.0,string-formatting,msxml6,Xml,Xslt 1.0,String Formatting,Msxml6,我们在XML中有一个数字,它在一个大的XML文件中最多可以达到3位,而这个文件必须转换为固定长度的文本才能加载到另一个系统中 我需要在输出中用前导零填充15的长度(这是固定长度的文本) 示例: - 1 becomes 000000000000001 - 11 becomes 000000000000011 - 250 becomes 000000000000250 我试过这个: <xsl:value-of select="substring(concat('000000000

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

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

示例:

 - 1 becomes   000000000000001
 - 11 becomes  000000000000011
 - 250 becomes 000000000000250
我试过这个:

<xsl:value-of select="substring(concat('000000000000000', msg:BankAccount/msg:Counter), 12, 15)"/>
我还尝试了
格式化数字
,但我发现它返回NaN

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

返回“NaN”

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

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

那就是

substring(
  concat('000000000000000', msg:BankAccount/msg:Counter), 
  string-length(msg:BankAccount/msg:Counter) + 1, 
  15
)
另一种方法是

substring(string(1000000000000000 + $x), 2)

也可以使用字符串格式完成

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

一般而言:

<xsl:value-of select="format-number(number_you_would_like_to_padd, 'string_how_much_zeros_you_would like')" />

另一个选项是


小提琴:

< P> >考虑……/P>的另一个选择。
<xsl:apply-templates select="Groups/Group[@Name='TheSource']/Field[@Name='BankAccount']" />
<xsl:text>999999999999999</xsl:text>
<!-- uncomment below and comment above line to use without test number -->
<!-- <xsl:text>|</xsl:text> -->

<xsl:template match="Groups/Group[@Name='BankAcctFile']/Field[@Name='BankAccount']">
    <xsl:call-template name="padleft">
        <xsl:with-param name="padChar" select="'0'" />
        <xsl:with-param name="padVar" select="substring(current(),1,15)" />
        <xsl:with-param name="length" select="15" />
    </xsl:call-template>
</xsl:template>

999999999999999

msg:Counter末尾是否有“劳埃德银行股份有限公司”?
format-number()
仅适用于数字。不,它只有一个数字,我保存在“LLOYDS BANK PLC”中,以显示错误原因的效果。如果msg:Counter是一个数字,则没有理由格式数字应返回NaN。您没有告诉我们一些错误。感谢您的帮助,非常感谢,我没有考虑检查len是的,我假设$x是一个数字,或者是一个将被转换成数字的值(具体取决于它是XPath1.0还是XPath2.0).非常优雅的解决方案完美。接受的答案对我不起作用,但这确实有效,而且更简洁!如果没有调用模板的内容,这无法提供问题的答案。上面添加了调用模板示例的内容。不,不是。
<xsl:number value="number_to_format" format="000000000000001"/>
<doc>
    <test>1</test>
    <test>11</test>
    <test>250</test>
</doc>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="test">
    <xsl:number value="." format="000000000000001"/>
    <xsl:text>&#xA;</xsl:text>
  </xsl:template>

</xsl:stylesheet>
000000000000001
000000000000011
000000000000250
<xsl:apply-templates select="Groups/Group[@Name='TheSource']/Field[@Name='BankAccount']" />
<xsl:text>999999999999999</xsl:text>
<!-- uncomment below and comment above line to use without test number -->
<!-- <xsl:text>|</xsl:text> -->

<xsl:template match="Groups/Group[@Name='BankAcctFile']/Field[@Name='BankAccount']">
    <xsl:call-template name="padleft">
        <xsl:with-param name="padChar" select="'0'" />
        <xsl:with-param name="padVar" select="substring(current(),1,15)" />
        <xsl:with-param name="length" select="15" />
    </xsl:call-template>
</xsl:template>