XSLT 乘法后保留尾随零

Retain trailing zeros after multiplication XSLT

我有一个问题,我需要在数学计算后保留尾随零。

例如:9854.32000 * 1 应该 return 9854.32000 而不是 9854.32。我尝试使用

<xsl:decimal-format name="test" decimal-separator="."/>

<xsl:value-of select="format-number(26825.8000 * 1, '#.000', 'test')"/>

但我想了解是否有一种方法可以让我通过计算尾随零的长度并将它们追加到结果中来实现这一点

请指教

可以计算出format-number()图片字符串。考虑以下示例:

XML

<input>
    <multiplicand>1</multiplicand>
    <multiplicand>2.0</multiplicand>
    <multiplicand>3.14</multiplicand>
    <multiplicand>4.000</multiplicand>
    <multiplicand>5.0000</multiplicand>
    <multiplicand>6.12345</multiplicand>
    <multiplicand>7.000000</multiplicand>
</input>

XSLT

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:param name="multiplier" select="2"/>

<xsl:template match="/input">
    <output>
        <xsl:for-each select="multiplicand">
            <xsl:variable name="zeros" select="translate(substring-after(., '.'), '123456789', '000000000')" />
            <product>
                <xsl:value-of select="format-number(. * $multiplier, concat('#.', $zeros))" />
            </product>
        </xsl:for-each>
    </output>
</xsl:template>

</xsl:stylesheet>

结果

<?xml version="1.0" encoding="UTF-8"?>
<output>
   <product>2</product>
   <product>4.0</product>
   <product>6.28</product>
   <product>8.000</product>
   <product>10.0000</product>
   <product>12.24690</product>
   <product>14.000000</product>
</output>