XSLT本地号码格式

时间:2016-11-02 10:38:27

标签: xslt-1.0

我尝试使用xslt format-number来格式化本地数字。我无法得到这个输出。

1
10
100
1,000
10,000
1,00,000
10,00,000
1,00,00,000
10,00,00,000

使用XSLT。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:variable name="t">123590</xsl:variable>
<xsl:template match="/">
<xsl:value-of select="format-number($t, '##,##,##0')"/>
</xsl:template>
</xsl:stylesheet>

感谢您的帮助。 Umesh制作

1 个答案:

答案 0 :(得分:0)

复制自:XSLT format-number with comma for indian price

XSLT中的浮点和整数INR数字格式

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:variable name="Value">301050101</xsl:variable>
<xsl:template match="/">

        <!-- 1
10
100
1,000
10,000
1,00,000
10,00,000
1,00,00,000
10,00,00,000 -->

    <xsl:choose>
        <xsl:when test="contains($Value,'.')">
            <xsl:variable name="integerValue" select="substring-before($Value,'.')"/>
            <xsl:variable name="floatValue" select="substring-after($Value,'.')"/>
            <!--                <xsl:value-of select="$integerValue"/>
            <xsl:value-of select="$floatValue"/> -->
            <xsl:call-template name="INR_Number_Format">
                <xsl:with-param name="integerValue" select="$integerValue"/>
            </xsl:call-template>
            <xsl:text>.</xsl:text>
            <xsl:value-of select="$floatValue"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:call-template name="INR_Number_Format">
                <xsl:with-param name="integerValue" select="$Value"/>
            </xsl:call-template>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template name="INR_Number_Format">
    <xsl:param name="integerValue"/>
    <xsl:choose>
        <xsl:when test="$integerValue >= 1000">
            <xsl:value-of select="format-number(floor($integerValue div 1000), '#,##')" />
            <xsl:text>,</xsl:text>
            <xsl:value-of select="format-number($integerValue mod 1000, '000')" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="format-number($integerValue, '#,###')" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

希望有帮助:)。