Answer 13: Number Formatting

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

   <xsl:template match="/">
    <html>
        <head>
           <title>Boiling Points</title>
        </head>
        <body>
        <h1>Boiling Points</h1>
        <table>
         <thead>
           <td>Atom</td>
           <td>Kelvin</td>
           <td>Celsius</td>
           <td>Fahrenheit</td>
         </thead>
          <xsl:apply-templates select="descendant::ATOM"/>
         </table>
         </body>
    </html>
  </xsl:template>

  <xsl:template match="ATOM">
    <tr>
      <td><xsl:value-of select="NAME"/></td>
      <td><xsl:value-of select="format-number(BOILING_POINT, '0.00')"/></td>
    <td><xsl:value-of select="format-number(BOILING_POINT - 273.15, '0.00')"/></td>
       <td><xsl:value-of select="format-number(9 div 5 * (BOILING_POINT - 273.15) + 32, '0.00')"/></td> 
    </tr>
  </xsl:template>
  
</xsl:stylesheet>

You can find this example in examples/prettyboilingpoints.xsl


View Transformed Document in Browser
Previous | Next | Top | Cafe con Leche

Copyright 2002 Elliotte Rusty Harold
Elliotte Rusty Harold
Last Modified October 16, 2002