format-number()
xsl:number
ELEMENT: xsl:decimal-format
<xsl:decimal-format
decimal-separator="character"
digit="character"
grouping-separator="character"
infinity="string"
minus-sign="character"
name="qname"
NaN="string"
pattern-separator="character"
percent="character"
per-mille="character"
zero-digit="character"
/>
The
xsl:decimal-format
element defines the symbols and characters used by the
format-number
function to convert numbers to strings.
This element can be used more than once, but with certain limitations. Each element can have an optional name value assigned to it by using by the
name
attribute. However, you cannot repeat name values. Further, you can only omit the
name
attribute once.
This element does not effect the behavior of the
xsl:number
and the
xsl:value-of
elements when they are used to format a number for display in the output. Nor does it effect the
string
function which has a default procedure for converting numbers to strings.
The
xsl:decimal-format
element can only be a child of the
xsl:stylesheet
or the
xsl:transform
elements.
This is a self-closing element and it cannot contain any child elements or any content.
decimal-separator="character"
The optional
decimal-separator
attribute defines what character is used to separate the integer and fraction part of a number. The default is a dot (.).
digit="character"
The optional
digit
attribute defines what character is used to signify that a digit is needed in a format pattern. The default is the hash mark (#).
grouping-separator="character"
The optional
grouping-separator
attribute defines what character is used to separate groups of digits (for example: 1,763,920). The default is a comma (,).
infinity="string"
The optional
infinity
attribute defines what string is used to represent that the value is infinite. The default is the string, "infinity".
minus-sign="character"
The optional
minus-sign
attribute defines what character is used to represent a minus sign. The default is the hyphen (-).
name="qname"
The optional
name
attribute assigns a qname to the element. If the
name
attribute is omitted, then you are declaring that this is the default
xsl:decimal-format
element. You cannot repeat names. Note that this name can be used as the optional third argument to the
format-number
function.
NaN="string"
The optional
NaN
attribute defines what string is used to indicate that the value is not a number. The default is the string, "NaN".
pattern-separator="character"
The optional
pattern-separator
attribute defines what character is used to separate positive and negative sub-patterns in a format pattern. The default is the semicolon (;).
percent="character"
The optional
percent
attribute defines what character is used to represent a percent sign. The default is the percent sign (%).
per-mille="character"
The optional
per-mille
attribute defines what character is used to represent the per thousand sign. The default is the Unicode per mille character ().
zero-digit="character"
The optional
zero-digit
attribute defines what character is used to represent the digit zero. The default is (0).
This code fragment shows how to format for European currency.
<
xsl:decimal-format name="euro_currency" decimal-separator="," grouping-separator="."
>
In this second example, we define "D" to represent a digit and display several numeric format variations.
Code for xslt_example_decimalformat.xsl:
<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>
Output:
Click to view output in separate window
- requires Internet Explorer
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information