<?xml version="1.0" encoding="UTF-8"?>

<!-- 更新履歴ページ用 XSL -->

<xsl:stylesheet version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns="http://www.w3.org/1999/xhtml"
	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:rss="http://purl.org/rss/1.0/"
	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 rss rdf dc xalan">

<xsl:import href="common.xsl"/>

<!-- ================ 出力設定 ================  -->

<xsl:output method="xml"
	encoding="Shift_JIS"
	omit-xml-declaration="no"
	doctype-public="-//W3C//DTD XHTML 1.1//EN"
	doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
	indent="yes"
	xalan:indent-amount="2"
	media-type="application/xhtml+xml"/>

<!-- ================ 各種設定 ================  -->

<xsl:param name="cssFile">toppage.css</xsl:param>

<!-- =======================================  -->

<xsl:template match="/h:html">
	<html xml:lang="ja">
	<xsl:apply-templates select="h:head"/>
	<body>
		<xsl:apply-templates select="h:h1/@*"/>
		<xsl:call-template name="navi"/>
		<xsl:apply-templates select="h:h1"/>
		<xsl:call-template name="navi"/>
		<xsl:call-template name="footer"/>
	</body>
	</html>
</xsl:template>

<xsl:template match="s:reflink"/>

<xsl:template match="s:reflink[1]">
	<xsl:apply-templates select="self::node()" mode="each-day"/>
</xsl:template>

<xsl:template match="s:reflink" mode="each-day">
	<div class="section" id="d{translate(@s:datetime, '-', '')}">
		<h3><xsl:apply-templates select="@s:datetime"/></h3>
		<dl>
			<xsl:apply-templates
				select="self::node() | following-sibling::s:reflink[@s:datetime = current()/@s:datetime]"
				mode="each-item"/>
		</dl>
	</div>
	<xsl:apply-templates
		select="following-sibling::s:reflink[@s:datetime != current()/@s:datetime][1]"
		mode="each-day"/>
</xsl:template>

<xsl:template match="s:reflink" mode="each-item">
	<dt>
		<xsl:variable name="linkToContentsPage">
			<xsl:if test="
					js:match(string(s:a/@href), '/^\/?[^\/]+/.+\.xml$/')
					and not(js:match(string(s:a/@href), '/^\/?[^\/]+/index.xml$/'))
					and not(js:match(string(s:a/@href), '/^\/?holyspring\/stair.xml$/'))">
				<s:a href="{js:replace(string(s:a/@href), '/^([^\/]+).*$/', '$1/index.xml')}"/>
				<xsl:text> ： </xsl:text>
			</xsl:if>
		</xsl:variable>
		<xsl:apply-templates select="xalan:nodeset($linkToContentsPage)"/>
		<xsl:apply-templates select="s:a"/>
		<xsl:apply-templates select="h:a"/>
		<xsl:if test="not(s:a) and not(h:a)">サイト内全般</xsl:if>
	</dt>
	<dd>
		<xsl:variable name="summary">
			<xsl:if test="string(s:a/@href)">
				<xsl:apply-templates
					select="document(concat($baseDir, '/', s:a/@href))/h:html/h:head/s:summary"/>
			</xsl:if>
		</xsl:variable>
		<xsl:variable name="content-pre">
			<xsl:copy-of select="xalan:nodeset($summary)"/>
			<xsl:choose>
				<xsl:when test="string($summary) and string(s:data)">
					<xsl:text> [</xsl:text>
					<xsl:apply-templates select="s:data"/>
					<xsl:text>]</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:apply-templates select="s:data"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:choose>
			<xsl:when test="string($content-pre)">
				<xsl:copy-of select="xalan:nodeset($content-pre)"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>新規作成あるいは更新。</xsl:text>
			</xsl:otherwise>
		</xsl:choose>
	</dd>
</xsl:template>

<xsl:template match="s:summary | s:data">
	<xsl:apply-templates/>
</xsl:template>

<xsl:template match="@s:datetime">
	<xsl:value-of select="js:n2DTF(string(self::node()))"/>
</xsl:template>

</xsl:stylesheet>
