Answer 7: Matching Elements in Namespaces

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

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

  <xsl:template match="chem:PERIODIC_TABLE">
    <body>
         <ul>
         <xsl:for-each select="chem:ATOM">
            <li><a href="#{chem:SYMBOL}"><xsl:value-of select="chem:NAME"/></a></li>
         </xsl:for-each>
         </ul>
        <xsl:apply-templates/>
      </body>
  </xsl:template>
  
  <xsl:template match="chem:ATOMIC_NUMBER">
    <li>Atomic Number: <xsl:value-of select="."/></li>
  </xsl:template>

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

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

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

 <xsl:template match="chem: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/atoms13.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