【问题标题】:XSLT 1.0 - Padding 0's with Math EquationXSLT 1.0 - 用数学公式填充 0
【发布时间】:2020-03-11 16:38:31
【问题描述】:

我试图用 XSLT 1.0 中相乘的变量来填充 XSLT 中的输出。我不能使用格式数字,因为它会自动对数字进行四舍五入,但我需要把小数放在适当的位置。当我在 XML 中使用列格式时,我可以让它工作,但由于它在 value-of-select 中有多种列格式,它似乎在这里不起作用并遵守下面代码中的 7:

            <xsl:value-of select="substring(E_BaseRate * E_NormalHours * 2, 1, 7)" disable-output-escaping="yes"/>

我得到的输出是:1601.93 翻译成 160193 但我需要得到 0160193 的结果。有没有办法做到这一点?

【问题讨论】:

  • “我不能使用格式数字,因为它会自动对数字进行四舍五入” 请提供此类问题的示例。一个minimal reproducible example
  • 当使用 format-number 时:我得到的结果是:0001602 这是四舍五入的结果:0160193
  • 所以乘以 200 而不是 2?目前尚不清楚问题的范围是什么。而且您的示例不是可重复的。

标签: xslt xslt-1.0


【解决方案1】:

我打破这个给你一个想法。您可以按原样使用,也可以将它们全部放在一个选择中...

  <xsl:variable name="numToString" select="string(160193)"/>

  <xsl:variable name="numLen" select="string-length($numToString)"/>

  <xsl:variable name="value" select="concat(substring('0000000', 1, 7 - $numLen), $numToString)"/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-29
    • 1970-01-01
    • 2012-11-22
    • 2016-01-21
    • 2023-04-08
    • 2013-12-05
    • 1970-01-01
    相关资源
    最近更新 更多