Answer 5: Attributes

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

  <xsl:template match="/">
    <html>
      <body>
        <xsl:apply-templates/>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="ATOM">
    <h2><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:text> </xsl:text><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 14, 2002