Grouping example: stylesheet

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

  <xsl:template match="/">
    <forwardslash>
      <xsl:apply-templates select="*"/>
    </forwardslash>
  </xsl:template>

  <xsl:template match="backslash">
    <xsl:for-each-group select="story" group-by="section">
      <section>
        <title><xsl:value-of select="current-group()/section"/></title>
        <xsl:apply-templates select="."/>
      </section>
    </xsl:for-each-group>
  </xsl:template>

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

  <xsl:template match="*">
    <xsl:copy-of select="."/>
  </xsl:template>

  <xsl:template match="section"/>

</xsl:stylesheet>

Previous | Next | Top | Cafe con Leche

Copyright 2002 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified February 18, 2001