<?xml version="1.0" encoding="utf-8"?>
<!-- XSL Transform from Atom 0.3 to XHTML 1.1 -->
<!-- Version 0.1 -->
<!-- Written by Aristotle Pagaltzis -->
<!-- This code is in the public domain -->
<xsl:stylesheet
	version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:atom="http://purl.org/atom/ns#"
	xmlns:date="http://exslt.org/dates-and-times"
	xmlns="http://www.w3.org/1999/xhtml"
	exclude-result-prefixes="atom date"
	extension-element-prefixes="date"
>

<xsl:output
	method="xml"
	indent="yes"
	omit-xml-declaration="yes"
	doctype-public="-//W3C//DTD XHTML 1.1//EN"
	doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
	encoding="iso-8859-1"
/>

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

<!-- default policy for elements is discard -->

<xsl:template match="node()|@*" />


<!-- define a few utility templates first of all -->

<xsl:template match="node()" mode="copy-checking-escaping">
	<xsl:value-of select="normalize-space(.)" />
</xsl:template>

<xsl:template match="node()[@mode='escaped']" mode="copy-checking-escaping">
	<xsl:value-of select="normalize-space(.)" disable-output-escaping="yes" />
</xsl:template>

<xsl:template match="node()" mode="make-link">
	<xsl:variable name="href"><xsl:value-of select="../atom:link[@rel='alternate']/@href" /></xsl:variable>
	<xsl:choose>
		<xsl:when test="$href">
			<a href="{$href}"><xsl:apply-templates select="." mode="copy-checking-escaping" /></a>
		</xsl:when>
		<xsl:otherwise>
			<xsl:apply-templates select="." mode="copy-checking-escaping" />
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template name="format-date">
	<!-- hooray for verbosity - sometimes I really love XSLT.. -->
	<xsl:param name="the-date" />
	<xsl:value-of select="date:month-abbreviation( $the-date )" />
	<xsl:text> </xsl:text>
	<xsl:value-of select="date:day-in-month( $the-date )" />
	<xsl:text>, </xsl:text>
	<xsl:value-of select="date:year( $the-date )" />
</xsl:template>


<!-- now we put the style in "stylesheet" -->

<xsl:param name="css-url" />

<xsl:template match="atom:entry/atom:summary">
	<div class="summary">
		<xsl:apply-templates select="." mode="copy-checking-escaping" />
	</div>
</xsl:template>

<xsl:template match="atom:entry/atom:content">
	<div class="content">
		<xsl:apply-templates select="." mode="copy-checking-escaping" />
	</div>
</xsl:template>

<xsl:template match="atom:entry">
	<li>
		<h2>
			<xsl:apply-templates select="atom:title" mode="make-link" /> 
			<span class="date">
				<xsl:text>(</xsl:text>
				<xsl:call-template name="format-date">
					<xsl:with-param name="the-date" select="atom:issued" />
				</xsl:call-template>
				<xsl:text>)</xsl:text>
			</span>
		</h2>
		<xsl:apply-templates select="atom:summary" />
		<xsl:apply-templates select="atom:content" />
	</li>
</xsl:template>

<xsl:template match="/atom:feed[@version = '0.3']">
	<html>
		<head>
			<title><xsl:apply-templates select="atom:title" mode="copy-checking-escaping" /></title>
			<xsl:if test="$css-url">
				<link rel="stylesheet" type="text/css" href="{$css-url}" />
			</xsl:if>
		</head>
		<body>
			<h1><xsl:apply-templates select="atom:title" mode="make-link" /></h1>
			<div id="tagline"><xsl:apply-templates select="atom:tagline" mode="copy-checking-escaping" /></div>
			<ul id="entries">
				<xsl:apply-templates select="atom:entry" />
			</ul>
		</body>
	</html>
</xsl:template>

</xsl:stylesheet>
