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

<!--Linebreak Code-->
<xsl:template name="break">
   <xsl:param name="text" select="."/>
   <xsl:choose>
   <xsl:when test="contains($text, '&#xa;')">
      <xsl:value-of select="substring-before($text, '&#xa;')"/>
      <br/>
      <xsl:call-template name="break">
          <xsl:with-param name="text" select="substring-after($text,
'&#xa;')"/>
      </xsl:call-template>
   </xsl:when>
   <xsl:otherwise>
	<xsl:value-of select="$text"/>
   </xsl:otherwise>
   </xsl:choose>
</xsl:template>

<xsl:template match="text">
   <xsl:call-template name="break"/>
</xsl:template>


<!--BEGIN THE TEMPLATE PROPER-->
<xsl:template match="/">
  <html>
  <head>
  <title><xsl:for-each select="/tinderbox/item[1]">
         <xsl:for-each select="attribute[@name='Name']">
	 <xsl:value-of select="current()"/>
	 </xsl:for-each>
	 </xsl:for-each>
  </title>
  <link type="text/css" rel="Stylesheet" href="tinderbox.css"/>
  </head>
  <body>
  <div align="center">
  <div id="contents">
  <!--Build the title-->
  <xsl:for-each select="/tinderbox/item[1]">
  	<xsl:for-each select="attribute[@name='Name']">
          <h1><a name="top"><xsl:value-of select="current()"/></a></h1>
	</xsl:for-each>
  </xsl:for-each>

  <!--BUILD THE INDEX-->
  <ol>
<xsl:for-each select="/tinderbox/item//item[position()>0]">
        <xsl:variable name="index" select="position()"/>
        <xsl:for-each select="attribute[@name='Name']">
	<li>    <a>
		<xsl:attribute name="href">
			#<xsl:value-of select="$index"/>		
		</xsl:attribute>		
		<xsl:value-of select="current()"/>
		</a></li>
	</xsl:for-each>
</xsl:for-each>
</ol>

    <xsl:for-each select="/tinderbox/item//item[position()>0]">
               <xsl:variable name="index" select="position()"/>
	<xsl:for-each select="attribute[@name='Name']">
	<a>
	   <xsl:attribute name="name">
	   	<xsl:value-of select="$index"/>
	   </xsl:attribute> 
	<div class="notetitle"><xsl:value-of select="current()"/></div>
	</a>
	</xsl:for-each>
	<div class="text">
	<!--Text-replace-->
	<xsl:apply-templates select="text"/>
	<!--Set the variable to the value of the text-->
	<div align="right"><a href="#top">top</a></div>
	</div>
	<!--End Text Replace-->
    </xsl:for-each>
    </div>
    </div>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>
