<html>
<head>
<title>&lt;xsl:decimal-format&gt;</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div id="Description">
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
<tr>
<td valign="top" class="NAME">&lt;xsl:decimal-format&gt;</td>
<td valign="top" class="COMPATIBILITY">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
</tr>
<tr>
<td valign="top" colspan="2" class="description">
Defines a number format to be used when writing numeric values to the output document. If the <span class="LITERAL">&lt;decimal-format&gt;</span> does not have a <span class="LITERAL">name</span>, it is assumed to be the default number format used for all output. On the other hand, if a number format is named, it can be referenced from the <span class="LITERAL">format-number()</span> function.</td></tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Category</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>Top-level element</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Required Attributes</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>None.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Optional Attributes</td>
</tr>
<tr>
<td colspan="2" class="description">
<dl>
<dt>
name
</dt>
<dd>
Gives a name to this format.
<P></p>
<dt>
decimal-separator
</dt>
<dd>
Defines the character (usually either a period or comma) used as the decimal point. This character is used both in the format string and in the output. The default value is the period character (
<span class="LITERAL">
.
</span>
).
<P></p>
<dt>
grouping-separator
</dt>
<dd>
Defines the character (usually either a period or comma) used as the thousands separator. This character is used both in the format string and in the output. The default value is the comma (
<span class="LITERAL">
,
</span>
).
<P></p>
<dt>
infinity
</dt>
<dd>
Defines the string used to represent infinity. Be aware that XSLT's number facilities support both positive and negative infinity. This string is used only in the output. The default value is the string
"
Infinity
"
.
<P></p>
<dt>
minus-sign
</dt>
<dd>
Defines the character used as the minus sign. This character is used only in the output. The default value is the hyphen character (
<span class="LITERAL">
-
</span>
, #x2D).
<P></p>
<dt>
NaN
</dt>
<dd>
Defines the string displayed when the value to be formatted is not a number. This string is used only in the output; the default value is the string
"
NaN
"
.
<P></p>
<dt>
percent
</dt>
<dd>
Defines the character used as the percent sign. This character is used both in the format string and in the output. The default value is the percent sign (
<span class="LITERAL">
%
</span>
).
<P></p>
<dt>
per-mille
</dt>
<dd>
Defines the character used as the per-mille sign. This character is used both in the format string and in the output. The default value is the Unicode per-mille character (#x2030).
<P></p>
<dt>
zero-digit
</dt>
<dd>
Defines the character used for the digit zero. This character is used both in the format string and in the output. The default is the digit zero (
<span class="LITERAL">
0
</span>
).
<P></p>
<dt>
digit
</dt>
<dd>
Defines the character used in the format string to stand for a digit. The default is the number sign character (
<span class="LITERAL">
#
</span>
).
<P></p>
<dt>
pattern-separator
</dt>
<dd>
Defines the character used to separate the positive and negative subpatterns in a pattern. The default value is the semicolon (
<span class="LITERAL">
;
</span>
). This character is used only in the format string.
<P></p>
</dl>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Content</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>None. <span class="LITERAL">&lt;xsl:decimal-format&gt;</span> is an empty element.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Appears in</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>
<span class="LITERAL">&lt;xsl:decimal-format&gt;</span> is a top-level element and can only appear as a child of <span class="LITERAL">&lt;xsl:stylesheet&gt;</span>.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Defined in</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>XSLT section 12.3, Number Formatting.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Example</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>Here is a stylesheet that defines two <span class="LITERAL">&lt;decimal-format&gt;</span>s:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
&lt;xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:months="Lookup table for month names"&gt;

  &lt;xsl:output method="text"/&gt;

  &lt;months:name sequence="01"&gt;January&lt;/months:name&gt;
  &lt;months:name sequence="02"&gt;February&lt;/months:name&gt;
  &lt;months:name sequence="03"&gt;March&lt;/months:name&gt;
  &lt;months:name sequence="04"&gt;April&lt;/months:name&gt;

  &lt;xsl:variable name="newline"&gt;
&lt;xsl:text&gt;
&lt;/xsl:text&gt;
  &lt;/xsl:variable&gt;

  &lt;xsl:decimal-format name="f1"
    decimal-separator=":"
    grouping-separator="/"/&gt;

  &lt;xsl:decimal-format name="f2"
    infinity="Really, really big"
    NaN="[not a number]"/&gt;

  &lt;xsl:template match="/"&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:text&gt;Tests of the &lt;decimal-format&gt; element:&lt;/xsl:text&gt;

    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:text&gt;   format-number(1528.3, '#/###:00', 'f1')=&lt;/xsl:text&gt;
    &lt;xsl:value-of select="format-number(1528.3, '#/###:00;-#/###:00', 'f1')"/&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:text&gt;   format-number(1 div 0, '###,###.00', 'f2')=&lt;/xsl:text&gt;
    &lt;xsl:value-of select="format-number(1 div 0, '###,###.00', 'f2')"/&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:text&gt;   format-number(blue div orange, '#.##', 'f2')=&lt;/xsl:text&gt;
    &lt;xsl:value-of select="format-number(blue div orange, '#.##', 'f2')"/&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:for-each select="report/month"&gt;
      &lt;xsl:text&gt;   &lt;/xsl:text&gt;
      &lt;xsl:value-of 
        select="document('')/*/months:name[@sequence=current()/@sequence]"/&gt;
      &lt;xsl:text&gt; - &lt;/xsl:text&gt;
      &lt;xsl:value-of select="format-number(miles-flown, '##,###')"/&gt;
      &lt;xsl:text&gt; miles flown, &lt;/xsl:text&gt;
      &lt;xsl:value-of select="format-number(miles-earned, '##,###')"/&gt;
      &lt;xsl:text&gt; miles earned.&lt;/xsl:text&gt;
      &lt;xsl:value-of select="$newline"/&gt;
      &lt;xsl:text&gt;     (&lt;/xsl:text&gt;
      &lt;xsl:value-of 
        select="format-number(miles-flown div sum(//miles-flown), '##%')"/&gt;
      &lt;xsl:text&gt; of all miles flown, &lt;/xsl:text&gt;
      &lt;xsl:value-of 
        select="format-number(miles-earned div sum(//miles-earned), '##%')"/&gt;
      &lt;xsl:text&gt; of all miles earned.)&lt;/xsl:text&gt;
      &lt;xsl:value-of select="$newline"/&gt;
      &lt;xsl:value-of select="$newline"/&gt;
    &lt;/xsl:for-each&gt; 
    &lt;xsl:text&gt;   Total miles flown: &lt;/xsl:text&gt;
    &lt;xsl:value-of select="format-number(sum(//miles-flown), '##,###')"/&gt;
    &lt;xsl:text&gt;, total miles earned: &lt;/xsl:text&gt;
    &lt;xsl:value-of select="format-number(sum(//miles-earned), '##,###')"/&gt;
  &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;</pre></span>
<p>We'll use this stylesheet against the following document:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0"?&gt;
&lt;report&gt;
  &lt;title&gt;Miles Flown in 2001&lt;/title&gt;
  &lt;month sequence="01"&gt;
    &lt;miles-flown&gt;12379&lt;/miles-flown&gt;
    &lt;miles-earned&gt;35215&lt;/miles-earned&gt;
  &lt;/month&gt;
  &lt;month sequence="02"&gt;
    &lt;miles-flown&gt;32857&lt;/miles-flown&gt;
    &lt;miles-earned&gt;92731&lt;/miles-earned&gt;
  &lt;/month&gt;
  &lt;month sequence="03"&gt;
    &lt;miles-flown&gt;19920&lt;/miles-flown&gt;
    &lt;miles-earned&gt;76725&lt;/miles-earned&gt;
  &lt;/month&gt;
  &lt;month sequence="04"&gt;
    &lt;miles-flown&gt;18903&lt;/miles-flown&gt;
    &lt;miles-earned&gt;31781&lt;/miles-earned&gt;
  &lt;/month&gt;
&lt;/report&gt;</pre></span>
<p>When we process this document with the stylesheet, here are the results:</p>
<span class="PROGRAMLISTING"><pre>

Tests of the &lt;decimal-format&gt; element:

   format-number(1528.3, '#/###:00', 'f1')=1/528:30
   format-number(1 div 0, '###,###.00', 'f2')=Really, really big
   format-number(blue div orange, '#.##', 'f2')=[not a number]

   January - 12,379 miles flown, 35,215 miles earned.
     (15% of all miles flown, 15% of all miles earned.)

   February - 32,857 miles flown, 92,731 miles earned.
     (39% of all miles flown, 39% of all miles earned.)

   March - 19,920 miles flown, 76,725 miles earned.
     (24% of all miles flown, 32% of all miles earned.)

   April - 18,903 miles flown, 31,781 miles earned.
     (22% of all miles flown, 13% of all miles earned.)

   Total miles flown: 84,059, total miles earned: 236,452</pre></span>
</td>
</tr>
</table>
</div>
</body>
</html>