XSLT format-number() Function
XSLT format-number() Function
The format-number function is used to convert a number into a string.
Syntax
string format-number(number,format,[decimalformat])
Input Parameters
Parameter | Required/Optional | Description |
---|---|---|
number | Required | Specifies the number to be formatted |
format | Required | Specifies the format pattern. Here are some of the characters used in the formatting pattern:
|
decimalformat | Optional. | A QName that matches the qname value of the name attribute of the xsl:decimal-format element |
Example
example.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:decimal-format name="staff" digit="D"/>
<xsl:template match="/">
<html>
<body>
<xsl:value-of select='format-number(123456789, "#.000000000")'/>
<br/>
<xsl:value-of select='format-number(123456789, "#.0")'/>
<br/>
<xsl:value-of select='format-number(0.123456789, "##%")'/>
<br/>
<xsl:value-of select='format-number(123456789, "################")'/>
<br/>
<xsl:value-of select='format-number(123456789, "D.0", "staff")'/>
<br/>
<xsl:value-of select='format-number(123456789, "$DDD,DDD,DDD.DD", "staff")'/>
<br/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
And the output is:
123456789.000000000
123456789.0
12%
123456789
123456789.0
$123,456,789