Answer 17:

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

  <xsl:template match="/">
    <html>
        <head>
           <title>Element Information</title>
        </head>
        <xsl:apply-templates/>
    </html>
  </xsl:template>

  <xsl:template match="PERIODIC_TABLE">
    <body>
         <ul>
         <xsl:for-each select="ATOM">
             <xsl:sort select="NAME"/>
            <li><a href="#{SYMBOL}"><xsl:value-of select="NAME"/></a></li>
         </xsl:for-each>
         </ul>
        <xsl:apply-templates  select="ATOM">
             <xsl:sort select="ATOMIC_NUMBER" data-type="number"/>
        </xsl:apply-templates>
      </body>
  </xsl:template>
  
  <xsl:template match="ATOM">
    <h2 id="{SYMBOL}"><xsl:value-of select="NAME"/> [<xsl:value-of select="SYMBOL"/>]</h2>
    <ul>
    <xsl:apply-templates select="ATOMIC_NUMBER"/>
    <xsl:apply-templates select="ATOMIC_WEIGHT"/>
    <xsl:apply-templates select="ATOMIC_RADIUS"/>
    <xsl:apply-templates select="ATOMIC_VOLUME"/>
    <xsl:apply-templates select="DENSITY"/>
    </ul>
  </xsl:template>

  <xsl:template match="ATOMIC_NUMBER">
    <li>Atomic Number: <xsl:value-of select="."/></li>
  </xsl:template>

 <xsl:template match="ATOMIC_WEIGHT">
    <li>Atomic Weight: <xsl:value-of select="."/></li>
  </xsl:template>

 <xsl:template match="DENSITY">
    <li>Density: <xsl:value-of select="."/> <xsl:value-of select="@UNITS"/></li>
  </xsl:template>

 <xsl:template match="ATOMIC_RADIUS">
    <li>Atomic radius: <xsl:value-of select="."/> <xsl:value-of select="@UNITS"/></li>
  </xsl:template>

 <xsl:template match="ATOMIC_VOLUME">
    <li>Atomic volume: <xsl:value-of select="."/> <xsl:value-of select="@UNITS"/></li>
  </xsl:template>
  
</xsl:stylesheet>
View Transformed Document in Browser
Previous | Next | Top | Cafe con Leche

Copyright 2002, 2003 Elliotte Rusty Harold
Elliotte Rusty Harold
Last Modified October 18, 2002