<?xml version='1.0' encoding='utf-8'?>

<!-- Copyright 2003 Aaron Isotton <aaron@isotton.com>.                    -->
<!-- Version 0.2.2, 2003-09-09.						  -->
<!-- Original at http://www.isotton.com/bookmarks/.                       -->
<!-- Distributed under the GNU GPL.                                       -->

<!-- Changelog:                                                           -->
<!--                                                                      -->
<!-- Version 0.2.2, 2003-09-09                                            -->
<!-- - changed doctype to HTML 4.01                                       -->
<!--                                                                      -->
<!-- Version 0.2.1, 2003-08-13                                            -->
<!-- - added border to bottom bar                                         -->

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

  <xsl:output method="html" encoding="us-ascii"
    doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
    doctype-system="http://www.w3.org/TR/html4/loose.dtd" indent="yes"/>

  <xsl:template match="/">
    <html>
    <head>
    <title><xsl:value-of select="xbel/title"/></title>
    <meta name="generator" content="Aaron Isotton's bookmark.xsl"/>
    <style type="text/css">
    body { font-family: sans-serif }
    div.sub-all { margin-left: 2em }
    div.sub-notitle { border: solid #999999; 
		      border-width: 0px 0px 0px 1px }
    div.bottom { text-align: center; font-size: smaller; border: solid black;
                 border-width: 1px 0px 0px 0px }
    h2, h3, h4, h5, h6, h7 { background: #F0F0F0; margin-bottom: 0px }
    ul.bookmarks { margin-top: 0px; padding-top: 1em }
    ul.bookmarks { list-style: disc }
    ul.toc { margin-top: 0px; padding-top: 1em }
    ul.toc { list-style: circle }
    </style> 
    </head>
    <body>
      <xsl:apply-templates select="xbel"/>
      <div class="bottom">
	<p>Generated by Aaron Isotton's bookmark.xsl, <a
href="http://www.isotton.com/bookmarks/">http://www.isotton.com/bookmarks/</a>.</p>
      </div>
    </body>
    </html>
  </xsl:template>

  <xsl:template name="generate-toc">
    <xsl:if test="folder">
      <xsl:element name="ul">
        <xsl:attribute name="class">toc</xsl:attribute>
        <xsl:attribute name="title">
          <xsl:text>Folders inside </xsl:text>
          <xsl:value-of select="title"/>
        </xsl:attribute>
        <xsl:for-each select="folder">
	  <xsl:if test="title != 'Bookmarklets' and title != 'Toolbar'">
	    <li>
	      <a href="#{generate-id(title)}">
		<xsl:value-of select="title"/>
	      </a>
	    </li>
	  </xsl:if>
        </xsl:for-each>
      </xsl:element>
    </xsl:if>
  </xsl:template>

  <xsl:template name="generate-bookmarks">
    <xsl:if test="bookmark">
      <xsl:element name="ul">
        <xsl:attribute name="class">bookmarks</xsl:attribute>
        <xsl:attribute name="title">
          <xsl:text>Bookmarks inside </xsl:text>
          <xsl:value-of select="title"/>
        </xsl:attribute>
        <xsl:for-each select="bookmark">
          <xsl:element name="li">
            <xsl:element name="a">
              <xsl:attribute name="href">
                <xsl:value-of select="@href"/>
              </xsl:attribute>
              <xsl:value-of select="title"/>
            </xsl:element>
	    <xsl:call-template name="generate-timestamp"/>
          </xsl:element>
        </xsl:for-each>
      </xsl:element>
    </xsl:if>
  </xsl:template>

  <xsl:template name="generate-timestamp">
    <xsl:if test="info/metadata/time_added">
      | Added:  <xsl:value-of select="info/metadata/time_added"/>
    </xsl:if>
    <xsl:if test="info/metadata/time_modified">
      | Modified:  <xsl:value-of select="info/metadata/time_modified"/>
    </xsl:if>
    <xsl:if test="info/metadata/time_visited">
      | Visited:  <xsl:value-of select="info/metadata/time_visited"/>
    </xsl:if>
  </xsl:template>

  <xsl:template match="xbel">
    <h1>
      <xsl:value-of select="title"/>
    </h1>

    <xsl:call-template name="generate-toc"/>
    <xsl:call-template name="generate-bookmarks"/>
    <xsl:apply-templates select="folder">
      <xsl:with-param name="depth" select="'2'"/>
    </xsl:apply-templates>
  </xsl:template>

  <xsl:template match="folder">
    <xsl:param name="depth"/>
    <xsl:if test="title != 'Toolbar' and title != 'Bookmarklets'">
      <div class="sub-all">
	<xsl:element name="h{$depth}">
	  <xsl:element name="a">
	    <xsl:attribute name="name">
	      <xsl:value-of select="generate-id(title)"/>
	    </xsl:attribute>
	    <xsl:value-of select="title"/>
	  </xsl:element>
	</xsl:element>
	<div class="sub-notitle">
	  <div class="content">
	    <xsl:call-template name="generate-toc"/>
	    <xsl:call-template name="generate-bookmarks"/>
	  </div>
	  <xsl:apply-templates select="folder">
	    <xsl:with-param name="depth">
	      <xsl:value-of select="$depth + 1"/>
	    </xsl:with-param>
	  </xsl:apply-templates>
	</div>
      </div>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>

