<?xml version='1.0'?>
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:output method='html' indent='yes' doctype-public='-//W3C//DTD HTML 3.2 FINAL//EN'/>

<!--
 - A straightforward template that emits a simple HTML page with a table 
 - at the top (generated by one template) and a body of links and link
 - descriptions below.
 -->
<xsl:template match='/'>
<html>
<head>
<title>Dreams Of A Rarebit Fiend</title>
<style>
body	{background:white;margin: 0px;font-family: Verdana, Arial, sans-serif;color: black;}
.blogtitle	{font-family: Verdana, Arial, sans-serif;color: white;font-size:36px;margin:2px;}
.links	{font-family: Verdana, Arial, sans-serif;color: black;font-size:11px;}
A.links:hover{color:white;}
A	{font-weight:bold;text-decoration:none;}
A:hover	{color:red;}
.subsection-link	{font-weight: normal;}
.date	{font-family: Verdana, Arial, sans-serif;color: black;font-size:11px;font-weight:bold;}
.posts	{font-family: Verdana, Arial, sans-serif;color: black;font-size:12px;}
.byline	{font-family: Verdana, Arial, sans-serif;color: #999999;font-size:11px;}
.bookTitle	{font-weight: bold;}
</style>
</head>
<body topmargin='0' leftmargin='0' marginwidth='0' marginheight='0'>
<div align="center">
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<xsl:text disable-output-escaping='yes'>
  &lt;%@ include file="header.html" %&gt;
</xsl:text>
  <tr>
    <td>
    <br/>
    <br/>
    <p>All the books, the software, and the links I absolutely cannot do without.</p>
    <p>If you want the raw source material used to produce this page, you can get the <a href="archives/Resources.opml">OPML outline</a> and the <a href="archives/resources.xsl">XSLT stylesheet</a> used to format that OPML to produce the HTML for this page. A tool like JOE (see below) can be used to quickly edit the OPML.</p>

    <xsl:apply-templates select='opml/body/outline' mode='links'/>
    <xsl:apply-templates select='opml/body/outline/outline' mode='body'/>

    <br/>
    <br/>
    </td>
  </tr>
</table>
</div>

</body>
</html>
</xsl:template>


<!-- 
 - This template matches a single category and generates links to the category
 - and each of the sub-sections under the category.
 -->
<xsl:template match='outline' mode='links'>
  <table width="100%">
  <xsl:for-each select='outline'>
    <xsl:if test='position() mod 2 = 1'>
      <tr>
        <!-- Generate a single row within the table. -->
        <xsl:call-template name='row'>
          <xsl:with-param name='position' select='position()'/>
          <xsl:with-param name='parent' select='..'/>
          <xsl:with-param name='times' select='2'/>
        </xsl:call-template>
      </tr>
    </xsl:if>
  </xsl:for-each>
  </table>
</xsl:template>

<xsl:template name='row'>
  <xsl:param name='position'/>
  <xsl:param name='parent'/>
  <xsl:param name='times'/>

  <xsl:if test='$times > 0'>
    <xsl:choose>
      <xsl:when test='$position > last()'>
        <td width="50%">&#160;</td>
      </xsl:when>
      <xsl:otherwise>
        <xsl:variable name='category' select='$parent/outline[$position]/@text'/>

        <td width="50%"><b><a>
        <xsl:attribute name='href'>#<xsl:value-of select='$category'/></xsl:attribute>
        <xsl:value-of select='$category'/></a></b><br/>
        <xsl:for-each select='$parent/outline[$position]/outline'>
          <!-- If we are past the first element in the list, insert a separator. -->
          <xsl:choose>
            <xsl:when test='position() > 1'>
              &#160;|&#160;
            </xsl:when>
          </xsl:choose>
          <a class="subsection-link">
          <xsl:attribute name='href'>#<xsl:value-of select='$category'/>/<xsl:value-of select='@text'/></xsl:attribute>
          <xsl:value-of select='@text'/></a>
        </xsl:for-each>
        </td>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:call-template name='row'>
      <xsl:with-param name='position' select='$position + 1'/>
      <xsl:with-param name='parent' select='$parent'/>
      <xsl:with-param name='times' select='$times - 1'/>
    </xsl:call-template>
  </xsl:if>
</xsl:template>

<!-- 
 - This template matches a single category and displays all of the body
 - material for that category. That includes a description of the category
 - (if any) and a set of described links for each of the sub-categories.
 -->
<xsl:template match='outline' mode='body'>
  <xsl:variable name='category' select='@text'/>

  <h2><a>
  <xsl:attribute name='name'><xsl:value-of select='$category'/></xsl:attribute>
  <xsl:value-of select='$category'/>
  </a></h2>

  <xsl:if test='@description != ""'>
  <p><xsl:value-of select='@description'/></p>
  </xsl:if>

  <xsl:for-each select='outline'>
    <h3><a>
      <xsl:attribute name='name'><xsl:value-of select='$category'/>/<xsl:value-of select='@text'/></xsl:attribute>
      <xsl:value-of select='@text'/>
    </a></h3>

    <xsl:if test='@description != ""'>
    <p><xsl:value-of select='@description'/></p>
    </xsl:if>

    <!-- 
     - The books sub-category gets special treatment. It's links are put out
     - with nice little book icons to the side rather than just as a list of
     - described links.
     -->
    <xsl:choose>
      <xsl:when test='@text = "Books"'>
        <table>
          <xsl:for-each select='outline'>
	    <tr>
              <td>
              <a>
              <xsl:attribute name='href'><xsl:value-of select='@url'/></xsl:attribute>
              <img border="0" alt="cover" hspace="3" vspace="3">
              <xsl:attribute name='src'>images/<xsl:value-of select='@image'/></xsl:attribute>
              </img>
              </a>
              </td>
              <td valign="top">
              <a>
              <xsl:attribute name='href'><xsl:value-of select='@url'/></xsl:attribute>
              <span class="booktitle"><xsl:value-of select='@text'/></span>
              </a>
              </td>
	    </tr>
          </xsl:for-each>
        </table>
      </xsl:when>
      <xsl:otherwise>
        <dl>
          <xsl:for-each select='outline'>
            <dt>
              <a><xsl:attribute name='href'><xsl:value-of select='@url'/></xsl:attribute>
              <xsl:value-of select='@text'/></a>
            </dt>
            <dd>
              <p>
                <xsl:if test='@openSource != ""'>
                  <b>Open Source: </b>
                  <xsl:value-of select='@openSource'/>
                  <xsl:if test='@license != ""'>
                    (<xsl:value-of select='@license'/> license)
                  </xsl:if>
                  <br/>
                </xsl:if>

                <xsl:for-each select='outline'>
                  <p><xsl:value-of select='@text'/></p>
                </xsl:for-each>
              </p>
            </dd>
          </xsl:for-each>
        </dl>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>
