<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:clahey="http://clahey.net/xslt/" version="1.0">
    <xsl:output method="html"/>

<!-- Bug code -->
    <xsl:template name="bug-element">
        <xsl:param name="bug"/>
	<a href="http://bugzilla.ximian.com/show_bug.cgi?id={$bug}">
	    <xsl:value-of select="$bug"/>
	</a>
    </xsl:template>
    <xsl:template name="bugs-element">
        <xsl:param name="bugs"/>
        <xsl:choose>
	    <xsl:when test="not($bugs)"/>
            <xsl:when test="contains($bugs, ' ')">
	        <xsl:call-template name="bug-element">
		    <xsl:with-param name="bug" select="substring-before($bugs, ' ')"/>
		</xsl:call-template>,
		<xsl:call-template name="bugs-element">
    		    <xsl:with-param name="bugs" select="substring-after($bugs, ' ')"/>
    		</xsl:call-template>
            </xsl:when>
	    <xsl:otherwise>
	        <xsl:call-template name="bug-element">
		    <xsl:with-param name="bug" select="$bugs"/>
		</xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template name="border">
        <xsl:param name="width" select="2"/>
        <xsl:param name="height" select="2"/>
        <xsl:param name="color" select="'black'"/>
        <xsl:param name="contents"/>
	<xsl:copy-of select="$contents"/>
<!--        <table cellspacing="0" cellpadding="0" border="0">
	    <tr><td bgcolor="black"><img src="blank.gif"
        width="2" height="2"/></td><td bgcolor="black"><img src="blank.gif" width="2" height="2"/></td><td bgcolor="black"><img src="blank.gif" width="2" height="2"/></td></tr>
	    <tr><td bgcolor="black"><img src="blank.gif" width="2" height="2"/></td><td><xsl:copy-of select="$contents"/></td><td bgcolor="black"><img src="blank.gif" width="2" height="2"/></td></tr>
	    <tr><td bgcolor="black"><img src="blank.gif" width="2" height="2"/></td><td bgcolor="black"><img src="blank.gif" width="2" height="2"/></td><td bgcolor="black"><img src="blank.gif" width="2" height="2"/></td></tr>
	    </table>-->
    </xsl:template>
<!-- Top level -->
    <xsl:template match="weblog">
	<xsl:variable name="process-blank" select="clahey:system('/bin/cp', 'src/blank.gif', 'output/')"/>
	<xsl:variable name="put-up-xml" select="clahey:system('/bin/cp', 'data/index.xml', 'src/process.xsl', 'output/')"/>
	<meta name="keywords" content="Chris Lahey,Christopher James Lahey"/>
        <html>
	    <head>
                <style type="text/css">
<xsl:comment>
    A:link{text-decoration:none; color: #0000f0}
    A:visited{text-decoration:none; color: #0000f0}
    A:active{text-decoration: none; color: #0000f0}
BODY {
   font-family: lucida, helvetica, sans-serif;
   font-size: 12pt;
}
TD, P, UL {
   font-family: lucida, helvetica, sans-serif;
   font-size: 12pt;
}

TT {
   font-family: fixed, lucidatypewriter, courier new;
   font-size: 12pt;
}

.NAVI {
   font-size: 10pt;
}

span.map {
   font-size: 10pt;
}
</xsl:comment>
                </style>
	        <title> Chris Lahey </title> 
	    </head>
	    <body bgcolor="#ffffff">
	        <xsl:apply-templates> <xsl:sort select="@date" order="descending"/> </xsl:apply-templates>
		<p align="center">
		    <a href="process.xsl">Show me the code.</a><br/><a href="index.xml">Show me the xml.</a>
		</p>
	    </body>
	</html>
    </xsl:template>

<!-- Handles copying unrecognized stuff. -->
    <xsl:template match="*">
        <xsl:copy><xsl:for-each select="attribute::*"><xsl:copy/></xsl:for-each><xsl:apply-templates/></xsl:copy>
    </xsl:template>

<!-- Picture -->
    <xsl:template match="picture">
        <xsl:variable name="image" select="string(@image)"/>
	<xsl:variable name="crop" select="@crop"/>
	<xsl:variable name="image-prefix" select="substring-before($image, '.jpg')"/>
	<xsl:variable name="thumbandsize" select="clahey:system('src/build-pics.pl', concat ('-crop=', $crop), $image)"/>
	<xsl:variable name="thumb" select="substring-before($thumbandsize, ' ')"/>
	<xsl:variable name="size" select="substring-after($thumbandsize, ' ')"/>
	<xsl:variable name="width" select="substring-before($size, ' ')"/>
	<xsl:variable name="height" select="substring-after($size, ' ')"/>
	<xsl:variable name="date" select="clahey:system('src/comp-date.pl', substring-before ($image, '-'))"/>
	<xsl:variable name="yp" select="@yp"/>
	<xsl:variable name="ypmap" select="@ypmap"/>
	<xsl:variable name="location" select="@location"/>
        <div>
	    <p align="center">
	    <xsl:call-template name="border">
	    <xsl:with-param name="contents">
	        <a href="{$image}"><img alt="{normalize-space()}" border="0" width="{$width}" height="{$height}" src="{$thumb}"/></a>
	    </xsl:with-param>
	    </xsl:call-template>
<br/>
	      <xsl:value-of select="$date"/>
	      <xsl:if test="$yp"><img src="blank.gif" width="20" height="1"/><span class="map"><a href="http://yp.yahoo.com/py/ypMap.py?{$yp}">map</a></span></xsl:if>
	      <xsl:if test="$ypmap"><img src="blank.gif" width="20" height="1"/><span class="map"><a href="http://maps.yahoo.com/py/ypMap.py?{$ypmap}">map</a></span></xsl:if>
	      <xsl:if test="$location">
	      	  <xsl:variable name="yp" select="key('location', $location)/@yp"/>
		  <xsl:variable name="ypmap" select="key('location', $location)/@ypmap"/>
		      <xsl:if test="$yp"><img src="blank.gif" width="20" height="1"/><span class="map"><a href="http://yp.yahoo.com/py/ypMap.py?{$yp}">map</a></span></xsl:if>
		      <xsl:if test="$ypmap"><img src="blank.gif" width="20" height="1"/><span class="map"><a href="http://maps.yahoo.com/py/ypMap.py?{$ypmap}">map</a></span></xsl:if>
	      </xsl:if>
	      <br/>
	      <xsl:apply-templates/>
	    </p>
        </div>
    </xsl:template>

    <xsl:template match="location">
    </xsl:template>
    <xsl:key match="location" name="location" use="@name"/>


<!-- Daily Entry -->
    <xsl:template match="entry">
        <xsl:variable name="date-string" select="string(attribute::date)"/>
	<xsl:variable name="year" select="substring-before($date-string, '-')"/>
	<xsl:variable name="month-num" select="number(substring-before(substring-after($date-string, '-'), '-'))"/>
	<xsl:variable name="day" select="substring-after(substring-after($date-string, '-'), '-')"/>
	<xsl:variable name="month-element">
            <xsl:choose>
	        <xsl:when test="$month-num=1">January</xsl:when>
		<xsl:when test="$month-num=2">February</xsl:when>
		<xsl:when test="$month-num=3">March</xsl:when>
		<xsl:when test="$month-num=4">April</xsl:when>
		<xsl:when test="$month-num=5">May</xsl:when>
		<xsl:when test="$month-num=6">June</xsl:when>
		<xsl:when test="$month-num=7">July</xsl:when>
		<xsl:when test="$month-num=8">August</xsl:when>
		<xsl:when test="$month-num=9">September</xsl:when>
		<xsl:when test="$month-num=10">October</xsl:when>
		<xsl:when test="$month-num=11">November</xsl:when>
		<xsl:when test="$month-num=12">December</xsl:when>
	    </xsl:choose>
	</xsl:variable>
	<xsl:variable name="month" select="string ($month-element)"/>
        <xsl:variable name="date" select="concat ($month, ' ', $day, ', ', $year)"/>
        <p>
    	    <a name="{$date-string}"/>
    	    <b> <u><xsl:value-of select="$date"/></u> </b>
    	    <p>
    	        <xsl:if test="@bugs">
    		    Fixed: <xsl:call-template name="bugs-element">
    			<xsl:with-param name="bugs" select="@bugs"/>
    		    </xsl:call-template>
    	        </xsl:if>
    	    </p>
    	    <div>
    		<xsl:apply-templates/>
    	    </div>
	</p>
    </xsl:template>
    <xsl:template match="sep">
        <br/><br/>
    </xsl:template>
    <xsl:template match="ref"> 
        <xsl:variable name="date" select="@date"/>
	<a href="#{$date}"><xsl:apply-templates/></a>
    </xsl:template>
</xsl:stylesheet>
