<?xml version="1.0" encoding="UTF-8"?>
<!-- ======================================================================
*  $Id: transform.xsl,v 1.10 2007/10/13 14:31:00 nzawa Exp nzawa $
*
*  Copyright (c) 2005 Nzawa
*
*  Usage of the works is permitted provided that this instrument
*  is retained with the works, so that any entity that uses the works
*  is notified of this instrument.
*
*  DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY. 
*
*  [2004, Fair License: rhid.com/fair]
 ====================================================================== -->
<xsl:stylesheet
	version="1.0"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	xmlns:rss="http://purl.org/rss/1.0/"
	exclude-result-prefixes="rdf rss">


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

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

<xsl:include href="config.xsl"/>
<xsl:include href="dublincore.xsl"/>
<xsl:include href="syndication.xsl"/>
<xsl:include href="content.xsl"/>

<xsl:template mode="ext_head" match="*"></xsl:template>
<xsl:template mode="ext_metadata" match="*"></xsl:template>
<xsl:template mode="ext_headline" match="*"></xsl:template>


<xsl:template match="/">
	<xsl:choose>
		<xsl:when test="//rdf:RDF/rss:channel">
			<xsl:apply-templates select="//rdf:RDF/rss:channel"/>
		</xsl:when>
		<xsl:otherwise>
			<!-- エラー処理を入れると幸せになれそう -->
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>


<xsl:template match="rss:channel">
	<html>
		<head>
			<xsl:call-template name="head"/>
		</head>
		<body>
			<xsl:call-template name="h1"/>
			<xsl:call-template name="metadata"/>
			<xsl:call-template name="headline"/>
			<xsl:call-template name="credit"/>
		</body>
	</html>
</xsl:template>


<xsl:template name="head">
	<meta name="description" content="{rss:description}"/>
	<link rel="alternate" href="{rss:link}" title="{rss:title}"/>
	<xsl:if test="$cfg_stylesheet_uri">
		<xsl:element name="link">
			<xsl:attribute name="rel">
				<xsl:text>stylesheet</xsl:text>
			</xsl:attribute>
			<xsl:attribute name="href">
				<xsl:value-of select="$cfg_stylesheet_uri"/>
			</xsl:attribute>
			<xsl:if test="$cfg_stylesheet_type">
				<xsl:attribute name="type">
					<xsl:value-of select="$cfg_stylesheet_type"/>
				</xsl:attribute>
			</xsl:if>
			<xsl:if test="$cfg_stylesheet_title">
				<xsl:attribute name="title">
					<xsl:value-of select="$cfg_stylesheet_title"/>
				</xsl:attribute>
			</xsl:if>
		</xsl:element>
	</xsl:if>
	<title>
		<xsl:value-of select="$cfg_title_prefix"/>
		<xsl:value-of select="rss:title"/>
		<xsl:value-of select="$cfg_title_suffix"/>
	</title>
	<xsl:apply-templates mode="ext_head"/>
</xsl:template>


<xsl:template name="h1">
	<xsl:if test="rss:image/@rdf:resource = ../rss:image/@rdf:about">
		<div>
			<xsl:choose>
				<xsl:when test="../rss:image/rss:link">
					<a href="{../rss:image/rss:link}"><img src="{../rss:image/rss:url}" alt="{../rss:image/rss:title}"/></a>
				</xsl:when>
				<xsl:otherwise>
					<img src="{../rss:image/rss:url}" alt="{../rss:image/rss:title}"/>
				</xsl:otherwise>
			</xsl:choose>
		</div>
	</xsl:if>
	<h1>
		<xsl:value-of select="$cfg_h1_prefix"/>
		<xsl:value-of select="rss:title"/>
		<xsl:value-of select="$cfg_h1_suffix"/>
	</h1>
</xsl:template>


<xsl:template name="metadata">
	<h2 id="{$cfg_metadata_id}">
		<xsl:value-of select="$cfg_metadata_heading"/>
	</h2>
	<dl>
		<dt>
			<xsl:text>対象</xsl:text>
		</dt>
		<dd>
			<a href="{rss:link}"><xsl:value-of select="rss:link"/></a>
		</dd>
		<dt>
			<xsl:text>説明</xsl:text>
		</dt>
		<dd>
			<xsl:value-of select="rss:description"/>
		</dd>
		<xsl:apply-templates mode="ext_metadata"/>
	</dl>
</xsl:template>


<xsl:template name="headline">
	<h2 id="{$cfg_headline_id}">
		<xsl:value-of select="$cfg_headline_heading"/>
	</h2>
	<dl>
		<xsl:variable name="channel_parent" select=".." />
		<xsl:for-each select="rss:items/rdf:Seq/rdf:li">
			<xsl:apply-templates select="$channel_parent/rss:item[@rdf:about = current()/@rdf:resource]"/>
		</xsl:for-each>
	</dl>
</xsl:template>


<xsl:template match="rss:item">
	<dt>
		<a href="{rss:link}"><xsl:value-of select="rss:title"/></a>
	</dt>
	<xsl:if test="rss:description">
		<dd><xsl:value-of select="rss:description"/></dd>
	</xsl:if>
	<xsl:apply-templates mode="ext_headline"/>
</xsl:template>


<xsl:template name="credit">
	<h2 id="{$cfg_credit_id}">
		<xsl:value-of select="$cfg_credit_heading"/>
	</h2>
	<address>
		<xsl:text>Copyright &#169; 2005 Nzawa</xsl:text><br/>
		<xsl:text>$Id: transform.xsl,v 1.10 2007/10/13 14:31:00 nzawa Exp nzawa $</xsl:text><br/>
		<xsl:value-of select="$cfg_credit_additional"/>
	</address>
</xsl:template>


</xsl:stylesheet>
