Answer 4: Applying Templates

<?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"/>
    </ul>
  </xsl:template>

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

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

You can find this example in examples/atoms8.xsl


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

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