<?xml version="1.0" encoding="UTF-8"?>

<!-- 更新履歴 RSS 用 XSL -->

<xsl:stylesheet version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns="http://purl.org/rss/1.0/"
	xmlns:h="http://www.w3.org/1999/xhtml"
	xmlns:s="http://www.remus.dti.ne.jp/~a-satomi/"
	xmlns:js="http://www.remus.dti.ne.jp/~a-satomi/jsfunc"
	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:xalan="http://xml.apache.org/xalan"
	exclude-result-prefixes="h s js xalan">

<xsl:import href="updatelog.xsl"/>

<!-- ================ 出力設定 ================  -->

<xsl:output method="xml"
	encoding="UTF-8"
	omit-xml-declaration="no"
	indent="yes"
	xalan:indent-amount="2"
	media-type="application/xml"/>

<!-- 余計な DOCTYPE 宣言が付くのをどうしても防げない。シェルスクリプトで除去処理。 -->

<!-- ================ 各種設定 ================  -->

<xsl:param name="rssFile">rss.rdf</xsl:param>
<xsl:param name="rssURI" select="concat($baseURI, '/', $rssFile)"/>
<xsl:param name="bannerURI" select="concat($baseURI, '/common/img/banner/nyan2h_ban.png')"/>

<!-- ================ メインテンプレ ================  -->

<xsl:template match="/h:html">
	<xsl:processing-instruction name="xml-stylesheet">
		<xsl:text>href=&quot;common/xsl/rss2html.xsl&quot; type=&quot;text/xsl&quot;</xsl:text>
	</xsl:processing-instruction>

	<rdf:RDF xml:lang="ja">
		<channel rdf:about="{$rssURI}">
			<title>娘娘飯店しるきぃうぇぶ更新情報</title>
			<link><xsl:value-of select="$baseURI"/>/</link>
			<description>「娘娘飯店しるきぃうぇぶ」の（ねこめしにっきを除く）コンテンツ更新状況、最近 15 項目。</description>
			<image rdf:resource="{$bannerURI}" />
			<dc:date><xsl:value-of select="js:getTime()"/></dc:date>
			<dc:creator>ありみかさとみ</dc:creator>
			<items>
				<rdf:Seq>
					<xsl:apply-templates select="s:reflink[position() &lt;= 15]" mode="rss-items"/>
				</rdf:Seq>
			</items>
		</channel>
		<image rdf:about="{$bannerURI}">
			<title>娘娘飯店しるきぃうぇぶ</title>
			<link><xsl:value-of select="$baseURI"/>/</link>
			<url><xsl:value-of select="$bannerURI"/></url>
		</image>
		<xsl:apply-templates select="s:reflink[position() &lt;= 15]" mode="each-item"/>
	</rdf:RDF>
</xsl:template>

<xsl:template match="s:reflink" mode="rss-items">
	<xsl:param name="uri">
		<xsl:call-template name="getURI">
			<xsl:with-param name="uri" select="*/@href"/>
		</xsl:call-template>
	</xsl:param>
	<rdf:li rdf:resource="{$uri}"/>
</xsl:template>

<xsl:template match="s:reflink" mode="each-item">
	<xsl:param name="uri">
		<xsl:call-template name="getURI">
			<xsl:with-param name="uri" select="*/@href"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="item">
		<xsl:apply-imports/>
	</xsl:param>

	<item rdf:about="{$uri}">
		<title><xsl:value-of select="xalan:nodeset($item)/h:dt"/></title>
		<link><xsl:value-of select="$uri"/></link>
		<description><xsl:value-of select="xalan:nodeset($item)/h:dd"/></description>
		<dc:date><xsl:value-of select="@s:datetime"/></dc:date>
	</item>
</xsl:template>

<xsl:template name="getURI">
	<xsl:param name="uri"/>
	<xsl:choose>
		<xsl:when test="starts-with($uri, 'http://')">
			<xsl:value-of select="$uri"/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="$baseURI"/>
			<xsl:value-of select="js:omitDirIndex(js:chsuffix(js:r2a('/index.xml', string($uri)), 'html'))"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

</xsl:stylesheet>
