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

<xsl:import href="vars.xsl"/>

<xsl:output method="html" encoding="iso-8859-1" 
            doctype-public="-//W3C//DTD HTML 4.01//EN"
            doctype-system="http://www.w3.org/TR/html4/strict.dtd"/>

<xsl:strip-space elements="*"/>

<xsl:variable name="filedata" select="document(/imagelist/@filedata)/filedata/file"/>
<xsl:variable name="today" select="document('update.xml')/date"/>

<xsl:variable name="title" select="/imagelist/header/title"/>
<xsl:template match="/">
<html>
<head>
<title><xsl:value-of select="$title"/></title>
<link rel="Validate" title="HTML Validate"
                href="http://validator.w3.org/check/referer"/>
<link rel="Validate" title="CSS Validate"
                href="http://jigsaw.w3.org/css-validator/check/referer"/>


<link rel="shortcut icon" href="/icon/face.ico"/>
<link rel="copyright" href="#copyright"/>
<link rel="index" href="nameindex.html"/>
<link rel="author" href="mailto:{$authoremail} ({$author})"/>
<link rel="stylesheet" type="text/css" title="Brief View" href="brief.css"/>
<link rel="alternate stylesheet" type="text/css" title="Verbose View" href="verbose.css"/>
<link rel="alternate stylesheet" type="text/css" title="Test View" href="test.css"/>

<xsl:if test="imagelist/header/back">
<link rel="Up" href="{imagelist/header/back/@href}"/>
</xsl:if>

<script type="text/javascript" src="/js/albumview.js"/>
</head>
<body>
<div class="stylechoice" id="verbosestyle">Switch to <a href="#" 
onclick="setActiveStyleSheet('Verbose View'); return false;">Verbose View</a></div>
<div class="stylechoice" id="briefstyle">Switch to <a href="#" 
onclick="setActiveStyleSheet('Brief View'); return false;">Brief View</a></div>
<div class="stylechoice" id="teststyle">Switch to <a href="#" 
onclick="setActiveStyleSheet('Test View'); return false;">Experimental View</a></div>

<xsl:apply-templates select="imagelist"/>
<hr class="clear"/>
</body>
</html>
</xsl:template>

<xsl:template match="firstn[@n>0]">
<xsl:variable name="n" select="@n"/>
<xsl:variable name="count" select="count(image)"/>
<xsl:choose>
<xsl:when test="$n>$count">
<xsl:apply-templates select="image"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="min" select="image[position()=$n]/@count"/>
<xsl:message>FirstN reached: <xsl:value-of select="concat($count,' ',$n,' ',$min)"/></xsl:message>
<xsl:apply-templates select="image[@count>=$min]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="start">
<p><em>Click on thumbnails to see full images</em></p>
</xsl:template>

<xsl:template match="imagelist">
<xsl:apply-templates select="header/back[1]"/>

<div class="body">
<h1><xsl:apply-templates select="$title"/></h1>
<xsl:apply-templates select="body"/>
<div style="clear:both"><!-- dummy for mozilla bug --></div>
</div>

<div class="sig">
<a name="copyright">Copyright 2003, Thomas Andrews</a>, <a href="mailto:{$authoremail}?Subject={$title}">thomas&#64;thomasoandrews.com</a>.<br/>
Generated from XML file <a href="images.xml">images.xml</a> and  <a href="filedata.xml">filedata.xml</a>, with <a href="images.xsl">images.xsl</a>.<br/>
Generated at <xsl:value-of select="$today"/>.
</div>
</xsl:template>

<xsl:template match="back">
<div class="back">Back to <a href="{@href}"><xsl:apply-templates/></a></div>
</xsl:template>

<xsl:template match="/imagelist/title">
<h1><xsl:apply-templates/></h1>
</xsl:template>

<xsl:template match="subset/title">
<h2><xsl:apply-templates/></h2>
</xsl:template>

<xsl:template match="image">

<xsl:variable name="alt">
<xsl:value-of select="normalize-space(title)"/>
<xsl:if test="@date">
<xsl:text>: </xsl:text><xsl:value-of select="@date"/>
</xsl:if>
</xsl:variable>

<xsl:variable name="file" select="@file"/>
<xsl:variable name="data" select="$filedata[@id=$file][1]"/>
<xsl:variable name="hitcount" select="$hitcountdata[@id=$file][1]"/>
<div class="entry">
<div class="imagelink"><a rel="fullsize" rev="thumbnail" href="{$file}" title="{$alt}"><img class="{@thumbclass}"
src="{$thumbs}/{$file}" alt="{$alt}"/>
</a>
</div>
<div class="imageheader">
<div class="imagename">
<a href="{$file}" title="{$alt}">
    <xsl:value-of select="$file"/>
</a></div>

<xsl:if test="@date">
    <div class="date"><xsl:value-of select="@date"/></div>
</xsl:if>

<xsl:if test="$data/@size">
<div class="filesize">
<xsl:value-of select="$data/@size"/>
<xsl:text>K</xsl:text>
</div>

<xsl:if test="$hitcount[@count]">
    <div class="count">
    <xsl:value-of select="$hitcount/@count"/> 
    <xsl:text> hit</xsl:text>
    <xsl:if test="$hitcount/@count!=1"><xsl:text>s</xsl:text></xsl:if>
    </div>
</xsl:if>

<xsl:if test="$data/@width and $data/@height">
    <div class="dimensions">
     <xsl:value-of select="$data/@width"/>&#215;<xsl:value-of select="$data/@height"/>
    </div>
</xsl:if>
</xsl:if>
</div>
<xsl:apply-templates/>
<hr class="clear"/>
</div>
</xsl:template>

<xsl:template match="image/title">
<div class="imagetitle"><xsl:apply-templates/></div>
</xsl:template>

<xsl:template match="note">
<div class="imagenote"><xsl:apply-templates/></div>
</xsl:template>

<xsl:template match="htmlfrag">
<xsl:copy-of select="*|text()"/>
</xsl:template>

<xsl:template match="link">
<a href="{@xref}"><xsl:apply-templates/></a>
</xsl:template>

<xsl:template match="em">
<em><xsl:apply-templates/></em>
</xsl:template>

</xsl:stylesheet>
