format number by locale : number « XSLT stylesheet « XML

Home
XML
1.CSS Style
2.SVG
3.XML Schema
4.XQuery
5.XSLT stylesheet
XML » XSLT stylesheet » number 
format number by locale



File: Data.xml
<?xml version="1.0"?>
<?xml-stylesheet href="Transform.xslt" type="text/xsl"?>

<format>
 <number>100</number>
 <number>1000</number>
 <number>10000</number>
 <number>100000</number>
 <number>1000000</number>
 <number>10000000</number>
 <number>100000000</number>
 <number>1000000000</number>
</format>


File: Transform.xslt

<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" />
  <xsl:decimal-format name="de" decimal-separator=","
    grouping-separator="." />
  <xsl:decimal-format name="fr" decimal-separator=","
    grouping-separator=" " />
  <xsl:decimal-format name="ru" decimal-separator=","
    grouping-separator=" " />
  <xsl:decimal-format name="uk" decimal-separator="."
    grouping-separator="," />
  <xsl:decimal-format name="us" decimal-separator="."
    grouping-separator="," />

  <xsl:template match="format">
    <html>
      <head>
        <title>Number Formatter</title>
        <style type="text/css">
          table {margin-left:auto;margin-right:autotd
          {text-align:right;padding: 5px 5px 5px 5pxh3
          {text-align:center}
        </style>
      </head>
      <body>
        <h3>Number Formatter</h3>
        <table rules="all">
          <thead>
            <tr>
              <th>Deutschland</th>
              <th>France</th>
              <th>
                &#x420;&#x43E;&#x441;&#x441;&#x438;&#x44f;
              </th>
              <th>United Kingdom</th>
              <th>United States</th>
            </tr>
          </thead>
          <tbody>
            <xsl:apply-templates select="number" />
          </tbody>
        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="number">
    <tr>
      <td>
        <xsl:value-of
          select="format-number(.,'.###,00&#x20AC;','de')" />
      </td>
      <td>
        <xsl:value-of
          select="format-number(.,' ###,00&#x20AC;','fr')" />
      </td>
      <td>
        <xsl:value-of
          select="format-number(.,' ###,00p.','ru')" />
      </td>
      <td>
        <xsl:value-of
          select="format-number(.,'&#xA3;,###.00','uk')" />
      </td>
      <td>
        <xsl:value-of
          select="format-number(.,'&#x24;,###.00','us')" />
      </td>
    </tr>
  </xsl:template>

</xsl:stylesheet>

Output:

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Number Formatter</title><style type="text/css">
          table {margin-left:auto;margin-right:autotd
          {text-align:right;padding: 5px 5px 5px 5pxh3
          {text-align:center}
        </style></head>
   <body>
      <h3>Number Formatter</h3>
      <table rules="all">
         <thead>
            <tr>
               <th>Deutschland</th>
               <th>France</th>
               <th>
                                  ??????
                                
               </th>
               <th>United Kingdom</th>
               <th>United States</th>
            </tr>
         </thead>
         <tbody>
            <tr>
               <td>100,00€</td>
               <td>100,00€</td>
               <td>100,00p.</td>
               <td>£100.00</td>
               <td>$100.00</td>
            </tr>
            <tr>
               <td>1.000,00€</td>
               <td>1 000,00€</td>
               <td>1 000,00p.</td>
               <td>£1,000.00</td>
               <td>$1,000.00</td>
            </tr>
            <tr>
               <td>10.000,00€</td>
               <td>10 000,00€</td>
               <td>10 000,00p.</td>
               <td>£10,000.00</td>
               <td>$10,000.00</td>
            </tr>
            <tr>
               <td>100.000,00€</td>
               <td>100 000,00€</td>
               <td>100 000,00p.</td>
               <td>£100,000.00</td>
               <td>$100,000.00</td>
            </tr>
            <tr>
               <td>1.000.000,00€</td>
               <td>1 000 000,00€</td>
               <td>1 000 000,00p.</td>
               <td>£1,000,000.00</td>
               <td>$1,000,000.00</td>
            </tr>
            <tr>
               <td>10.000.000,00€</td>
               <td>10 000 000,00€</td>
               <td>10 000 000,00p.</td>
               <td>£10,000,000.00</td>
               <td>$10,000,000.00</td>
            </tr>
            <tr>
               <td>100.000.000,00€</td>
               <td>100 000 000,00€</td>
               <td>100 000 000,00p.</td>
               <td>£100,000,000.00</td>
               <td>$100,000,000.00</td>
            </tr>
            <tr>
               <td>1.000.000.000,00€</td>
               <td>1 000 000 000,00€</td>
               <td>1 000 000 000,00p.</td>
               <td>£1,000,000,000.00</td>
               <td>$1,000,000,000.00</td>
            </tr>
         </tbody>
      </table>
   </body>
</html>

 
Related examples in the same category
1.Add number list to the output
2.Output number and count
3.Output Number from any level
4.number column
5.Illustrates use of xsl:number element
6.number count="name" format=" 1. "
7.number level="multiple" count="*" from="data" format="1.1.1 "
8.number value="1000000" grouping-size="3" grouping-separator="."
9.number from="section" level="multiple" count="section | item" format=" a "
10.number format=" " grouping-size="3" grouping-separator=","
11.number format=" 1. "
12.number level="multiple" count="section | item" format="i. a. "
13.number count="manufacturer|car" level="multiple" format="1.1. "
14.number count="manufacturer" level="multiple" format="1."
15.number count="car" level="single" format="w"
16.number level="multiple" count="chapter|sect1|sect2|sect3" format="1.1.1.1. "
17.number level="any" count="chapter|sect1|sect2|sect3" format="1. "
18.number level="single" count="chapter|sect1|sect2|sect3" format="1.1.1.1. "
19.number level="multiple" count="chapter|sect1|sect2" format="I-A-i: "
20.number level="any" from="book" count="chapter" format="1."
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.