2013-12-14 31 views
0

數字格式我有一個數字,如:457342137,但我想將其顯示爲457 342 137空間在XSL

我有這樣的事情:

<xsl:template match="klient/@numer_telefonu"> 
     <xsl:variable name="numer" select="." /> 
     <xsl:value-of select="format-number($numer, '###&nbsp;###&nbsp;###')" /> 
    </xsl:template> 

,但它不工作。

回答

3

電話號碼是字符串,而不是號碼而且您不應該嘗試將其格式化爲一個格式。從技術上講,你可以這樣做:

<xsl:value-of select="translate(format-number(., '#,###'), ',', ' ')" /> 

在您的示例中實現所需的結果。但是,給定一個「數字」,如「057342137」,結果將是「57 342 137」(剝離前導零)。您應該使用字符串函數來操縱字符串。

2

如果你想使用一個非標準的「分組」分隔符,你首先需要定義你要在你的格式命令使用符號如下:

<xsl:decimal-format name="spaces" grouping-separator=" " /> 

然後,你可以參考一下這種格式在命令本身如下:

<xsl:value-of select="format-number($numer, '# ###', 'spaces')" /> 

十進制格式可以在http://www.w3.org/TR/xslt#format-number

01中找到進一步的信息