Answer 12: Node-set Functions

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

   <xsl:template match="/">
    <html>
        <head>
           <title>First Paragraphs</title>
        </head>
        <body>
          <xsl:apply-templates select="chapter"/>
         </body>
    </html>
  </xsl:template>

  <xsl:template match="chapter">
    <p>
      <xsl:value-of select="para[position() = 1]"/>
    </p>
    <xsl:apply-templates select="sect1"/>
  </xsl:template>
  
  <xsl:template match="sect1">
    <h1><xsl:value-of select="title"/></h1>
    <p>
      <xsl:value-of select="para[position() = 1]"/>
    </p>
    <xsl:apply-templates select="sect2"/>
  </xsl:template>
  
  <xsl:template match="sect2">
    <h2><xsl:value-of select="title"/></h2>
    <p>
      <xsl:value-of select="para[position() = 1]"/>
    </p>
    <xsl:apply-templates select="sect3"/>
  </xsl:template>
  
  <xsl:template match="sect3">
    <h3><xsl:value-of select="title"/></h3>
    <p>
      <xsl:value-of select="para[position() = 1]"/>
    </p>
    <xsl:apply-templates select="sect4"/>
  </xsl:template>
  
 <xsl:template match="sect4">
    <h4><xsl:value-of select="title"/></h4>
    <p>
      <xsl:value-of select="para[position() = 1]"/>
    </p>
    <xsl:apply-templates select="sect5"/>
  </xsl:template>
  
 <xsl:template match="sect5">
    <h5><xsl:value-of select="title"/></h5>
    <p>
      <xsl:value-of select="para[position() = 1]"/>
    </p>
    <xsl:apply-templates select="sect6"/>
  </xsl:template>
  
 <xsl:template match="sect6">
    <h6><xsl:value-of select="title"/></h6>
    <p>
      <xsl:value-of select="para[position() = 1]"/>
    </p>
  </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