<?xml version="1.0" encoding='UTF-8'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"   
		xmlns="http://www.w3.org/1999/xhtml"
		version = "1.0">

  <xsl:output method         = "html" />
  <xsl:output encoding       = "UTF-8" />
  <xsl:output indent         = "yes" />
  <xsl:output doctype-public = "-//W3C//DTD XHTML 1.1//EN" />
  <xsl:output doctype-system = "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" />

  <xsl:template match =  "/"> 

    <html>
      <head>
	<xsl:attribute name = "x:lang">en-ca</xsl:attribute>
	
	<xsl:copy-of select = "/html/head/base" />
	
	<title>
	  <xsl:text>[this is aaronland] </xsl:text>
	  <xsl:value-of select = "/html/head/title" />
	</title>
	
	<xsl:for-each select = "/html/head/child::node()[name()='meta']">
	  <xsl:copy-of select = "." />
	</xsl:for-each>
	
	<meta>
	  <xsl:attribute name = "name">MSSmartTagsPreventParsing</xsl:attribute>
	  <xsl:attribute name = "content">TRUE</xsl:attribute>
	</meta>
	
	<xsl:for-each select = "/html/head/child::node()[name()='link']">
	  <xsl:copy-of select = "." />
	</xsl:for-each>

	<link>
	  <xsl:attribute name="rel">alternate</xsl:attribute>
	  <xsl:attribute name="type">application/atom+xml</xsl:attribute>
	  <xsl:attribute name="title">this is aaronland Atom feed</xsl:attribute>
	  <xsl:attribute name="href">
	    <xsl:value-of select="/html/head/base/@href" />
	    <xsl:text>/weblog/syndication/atom-0.3.xml</xsl:text>
	  </xsl:attribute>
	</link>

	<link>
	  <xsl:attribute name="rel">alternate</xsl:attribute>
	  <xsl:attribute name="type">application/rdf+xml</xsl:attribute>
	  <xsl:attribute name="title">this is aaronland RSS 1.0 feed</xsl:attribute>
	  <xsl:attribute name="href">
	    <xsl:value-of select="/html/head/base/@href" />
	    <xsl:text>/weblog/syndication/rss-1.0.xml</xsl:text>
	  </xsl:attribute>
	</link>

	<link>
	  <xsl:attribute name="rel">alternate</xsl:attribute>
	  <xsl:attribute name="type">application/rdf+xml</xsl:attribute>
	  <xsl:attribute name="title">this is aaronland RSS 2.0 feed</xsl:attribute>
	  <xsl:attribute name="href">
	    <xsl:value-of select="/html/head/base/@href" />
	    <xsl:text>/weblog/syndication/rss-2.0.xml</xsl:text>
	  </xsl:attribute>
	</link>
	
	<link>
	  <xsl:attribute name = "rel">stylesheet</xsl:attribute>
	  <xsl:attribute name = "href">/css/weblog/brown.css</xsl:attribute>
	  <xsl:attribute name = "type">text/css</xsl:attribute>
	  <xsl:attribute name = "media">screen</xsl:attribute>
	</link>

	<xsl:if test="count(/html/body/div[@id='content']/ins[@class='post']/ins[@class='content']/child::node()[name()='img' and starts-with(@class,'picture')])">
	  <link>
	    <xsl:attribute name = "rel">stylesheet</xsl:attribute>
	    <xsl:attribute name = "href">/css/display/pictures.css</xsl:attribute>
	    <xsl:attribute name = "type">text/css</xsl:attribute>
	    <xsl:attribute name = "media">screen</xsl:attribute>
	  </link>
	  
	  <style>
	    <xsl:attribute name="type">
	      <xsl:text>text/css</xsl:text>
	    </xsl:attribute>

	    <xsl:for-each select="/html/body/div[@id='content']/ins[@class='post']/ins[@class='content']/child::node()[name()='img' and starts-with(@class,'picture')]">
	      <xsl:text>#</xsl:text>
	      <xsl:value-of select="@id" />
	      <xsl:text> { background-image:url('</xsl:text>
	      <xsl:value-of select="@src" />
	      <xsl:text>'); background-color:#fff;height:</xsl:text>
	      <xsl:value-of select="@height" />
	      <xsl:text>px;width:</xsl:text>
	      <xsl:value-of select="@width" />
	      <xsl:text>px; }</xsl:text>
	    </xsl:for-each>
	  </style>
	</xsl:if>
	
	<xsl:for-each select = "/html/head/child::node()[name()='style']">
	  <xsl:copy-of select = "." />
	</xsl:for-each>
	
	<script>
	  <xsl:attribute name = "src">/js/weblog/brown.js</xsl:attribute>
	  <xsl:attribute name = "type">text/javascript</xsl:attribute>
	  <xsl:comment>/* Internet Explorer, bite me... */</xsl:comment>
	</script>

	<script>
	  <xsl:attribute name = "src">/js/XHConn.js</xsl:attribute>
	  <xsl:attribute name = "type">text/javascript</xsl:attribute>
	  <xsl:comment>/* Internet Explorer, bite me... */</xsl:comment>
	</script>

	<xsl:for-each select = "/html/head/child::node()[name()='script']">
	  <xsl:copy-of select = "." />
	</xsl:for-each>
	
      </head>
      <body>

	<xsl:attribute name="style">
	  <xsl:text>background-image: url(</xsl:text>
	  <xsl:value-of select="/html/body/div[@id='content']/img[@id='splash']/@src" />
	  <xsl:text>);</xsl:text>
	</xsl:attribute>

	<div>
	  <xsl:attribute name="id">content</xsl:attribute>	

	  <div>
	    <xsl:attribute name="class">title</xsl:attribute>
	    <p>this is still aaronland</p>
	  </div>

	  <xsl:call-template name="nextprev" />
	  
	  <xsl:choose>
	    <xsl:when test="count(/html/body/div[@id='content']/ins[@class='post'])">
	      <xsl:call-template name="show_chunks" />
	    </xsl:when>
	    <xsl:otherwise>
	      <xsl:call-template name="sidebar" />
	    </xsl:otherwise>
	  </xsl:choose>

	</div>

	<div class="footer">
	  
	  <div class="rolling">
	    <img src="http://aaronland.net/img/misc/rolling_love_button.jpg" />
	  </div>
	  
	  <div class="aaronlinks">
	    <ul>
	      <li><a href="http://www.aaronland.info/">code</a>&#160;&#160;</li>
	      <li><a href="http://www.aaronland.net/">art</a>&#160;&#160;</li>
	      <li><a href="http://www.aaronstraupcope.com/resume/">r&#233;sum&#233;</a>&#160;&#160;</li>
	      <li><a href="http://www.eatdrinkfeelgood.org/">eatdrinkfeelgood</a></li>
            </ul>
	    
	    this is still aaronland
	  </div>
	</div>
	
      </body>
    </html>

  </xsl:template>
  
  <xsl:template name="show_chunks">
    
    <xsl:for-each select="/html/body/div[@id='content']/ins[@class='post']/ins[@class='content']">

      <xsl:variable name="id">
	<xsl:value-of select="parent::node()/@id" />
      </xsl:variable>

      <xsl:variable name="chunkid">
	<xsl:text>chunk-</xsl:text>
	<xsl:value-of select="$id" />
      </xsl:variable>

      <div>
	<xsl:attribute name="class">chunkwrapper</xsl:attribute>

	<xsl:attribute name="id">
	  <xsl:value-of select="$chunkid" />
	</xsl:attribute>
	
	<xsl:attribute name="onmouseover">
	  <xsl:text>show_chunk('</xsl:text>
	  <xsl:value-of select="$chunkid" />
	  <xsl:text>');</xsl:text>
	</xsl:attribute>

	<xsl:attribute name="onmouseout">
	  <xsl:text>hide_chunk('</xsl:text>
	  <xsl:value-of select="$chunkid" />
	  <xsl:text>');</xsl:text>
	</xsl:attribute>

	<div>
	  <xsl:attribute name="class">chunkborder</xsl:attribute>
	  <div>
	    <xsl:attribute name="class">chunk</xsl:attribute>

	    <xsl:for-each select="child::node()">
	      <xsl:choose>
		<xsl:when test="name()='img' and starts-with(@class,'picture')">
		  <xsl:call-template name="picture" />
		</xsl:when>
		<xsl:otherwise>
		  <xsl:copy-of select="." />
		</xsl:otherwise>
	      </xsl:choose>
	    </xsl:for-each>

	  </div>
	</div>
	
	<div>
	  <xsl:attribute name="class">metachunk</xsl:attribute>
	  <!-- busted; needs to return unique URLs for current
	       ins[@class='post'] node...
	       
	  <xsl:if test="count(descendant-or-self::*[name()='a'])">
	    <ul>
	      <xsl:attribute name="class">extrefs</xsl:attribute>
	      <xsl:for-each select="descendant-or-self::*[name()='a']">

		<xsl:message>
		  <xsl:value-of select ="name()" />
		  <xsl:text>: </xsl:text>
		  <xsl:value-of select="@href" />
		</xsl:message>

		<li>
		  <a>
		    <xsl:attribute name="href">
		      <xsl:value-of select="@href" />
		    </xsl:attribute>
		    <xsl:value-of select="@href" />
		  </a>
		</li>
	      </xsl:for-each>
	      </ul>
	  </xsl:if>
	  -->

	  <a>
	    <xsl:attribute name="href">
	      <xsl:value-of select="/html/head/base" />
	      <xsl:value-of select="/html/head/link[@rel='dc.identifier']/@href" />		
	      <xsl:text>#</xsl:text>
	      <xsl:value-of select="$id" />
	    </xsl:attribute>
	    <xsl:text>#</xsl:text>
	    <xsl:value-of select="$id" />  
	  </a>
	</div>

      </div>

      <xsl:if test="position()=1">
	<xsl:call-template name="sidebar" />
      </xsl:if>

    </xsl:for-each>
  </xsl:template>

  <xsl:template name="sidebar">
    <div>
      <xsl:attribute name="id">sidebar</xsl:attribute>
      <xsl:attribute name="class">chunkwrapper</xsl:attribute>
      <xsl:attribute name="style">display:none;</xsl:attribute>		  

      <xsl:attribute name="onmouseover">
	<xsl:text>show_chunk('sidebar');</xsl:text>
      </xsl:attribute>
      
      <xsl:attribute name="onmouseout">
	<xsl:text>hide_chunk('sidebar');</xsl:text>
      </xsl:attribute>
      
      <div>
	<xsl:attribute name="class">chunkborder</xsl:attribute>
	<div>
	  <xsl:attribute name="class">chunk</xsl:attribute>
	  <xsl:attribute name="id">sidebar_content</xsl:attribute>
	  
	</div>
      </div>
    </div>

    <script>
      <xsl:attribute name = "src">/js/weblog/sidebar.js</xsl:attribute>
      <xsl:attribute name = "type">text/javascript</xsl:attribute>
      <xsl:comment>/* Internet Explorer, bite me... */</xsl:comment>
    </script>

  </xsl:template>

  <xsl:template name="picture">
    <div>
      <xsl:attribute name="class">
	<xsl:value-of select="@class" />
      </xsl:attribute>
      <span>
	<xsl:attribute name="class">
	  <xsl:text>image</xsl:text>
	</xsl:attribute>
	<xsl:attribute name="id">
	  <xsl:value-of select="@id" />
	</xsl:attribute>
	<xsl:text> </xsl:text>
      </span>
      <span>
	<xsl:attribute name="caption">
	  <xsl:value-of select="@alt" />
	</xsl:attribute>
      </span>
    </div>
  </xsl:template>

  <xsl:template name="nextprev">
    <xsl:if test="/html/head/link[@rel='next'] or /html/head/link[@rel='prev']">
      <div>
	<xsl:attribute name="id">
	  <xsl:text>nextprev</xsl:text>
	</xsl:attribute>

	<xsl:call-template name="nextprev_link">
	  <xsl:with-param name="name" select="'prev'" />
	  <xsl:with-param name="alt" select="'pronto!'" />
	</xsl:call-template>

	<xsl:call-template name="nextprev_link">
	  <xsl:with-param name="name" select="'next'" />
	  <xsl:with-param name="alt" select="'basta!'" />
	</xsl:call-template>
      </div>
    </xsl:if>
  </xsl:template>

  <xsl:template name="nextprev_link">
    <xsl:param name="name" />
    <xsl:param name="alt" />

    <div>
      <xsl:attribute name="id">
	<xsl:value-of select="$name" />
      </xsl:attribute>

      <xsl:choose>
	<xsl:when test="/html/head/link[@rel=$name]">
	  <a>
	    <xsl:attribute name="href">
	      <xsl:value-of select="/html/head/link[@rel=$name]/@href" />
	    </xsl:attribute>
	    <q>
	      <xsl:value-of select="/html/head/link[@rel=$name]/@title" />
	    </q>
	  </a>
	</xsl:when>
	<xsl:otherwise>
	  <xsl:value-of select="$alt" />
	</xsl:otherwise>
      </xsl:choose>
    </div>
  </xsl:template>

</xsl:stylesheet>
