Answer 6: Iteration

<?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">
            <li><a href="#{SYMBOL}"><xsl:value-of select="NAME"/></a></li>
         </xsl:for-each>
         </ul>
        <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>

You can find this example in examples/atoms12.xsl


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

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