【问题标题】:xsl - format-number from one to two digits 1 => 01xsl - 从一位到两位数的格式数字 1 => 01
【发布时间】:2016-09-21 13:39:25
【问题描述】:

在 XSLT 中是否有一些函数或一些东西来允许低格式数字 比如 1 会变成 01

如果我有

<a>10</a>
<b>5</b>

它们会显示为

A10

and

B05

【问题讨论】:

  • A”和“B”字符应该从哪里来?

标签: xslt xsl-fo


【解决方案1】:

函数Formating numbers

<xsl:template match="root/*">
    <xsl:value-of select="format-number(.,'00')"/>
</xsl:template>

XSLT 1.0 大写的节点名:

<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />

<xsl:value-of select="translate(name(), $smallcase, $uppercase)" />

综合:

<xsl:value-of select="concat(translate(name(), $smallcase, $uppercase), format-number(.,'00'))" />

【讨论】:

    【解决方案2】:
    format-number(5, '00')
    

    返回“05”。

    同样,

    format-number(10, '00')
    

    返回“10”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-07
      • 2020-10-12
      • 1970-01-01
      • 2011-06-04
      • 2011-09-09
      • 2012-06-02
      相关资源
      最近更新 更多