<?xml version="1.0" encoding="UTF-8"?>

<!-- 日記見出しリスト作成（時系列降順） -->

<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:fl="http://www.remus.dti.ne.jp/~a-satomi/filelist"
	xmlns:xalan="http://xml.apache.org/xalan"
	exclude-result-prefixes="h s js fl 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="curFilePath"/><!-- シェルスクリプトからの Xalan 起動時に -param オプションにて付与 -->
<xsl:param name="nikkiDirPath" select="js:omitDirIndex($curFilePath)"/>
<xsl:param name="nikkiDirFPath" select="concat($baseDir, $nikkiDirPath)"/>
<xsl:param name="year" select="substring-before(substring-after($nikkiDirPath, concat($curDirName, '/')), '/')"/>
<xsl:param name="pageTitle">ねこめしにっき見出し一覧 (<xsl:value-of select="$year"/>年)</xsl:param>
<xsl:param name="cssFile">nikki.css</xsl:param>

<!-- ================ メインテンプレ ================  -->

<xsl:template match="/">

	<html xml:lang="ja">
		<xsl:call-template name="head"/>
	<body class="indexPage">
		<xsl:call-template name="navi"/>
		<div class="section">
			<h1><xsl:value-of select="$pageTitle"/></h1>
			<xsl:call-template name="extract-headings"/>
		</div>
		<xsl:call-template name="navi"/>
		<xsl:call-template name="footer"/>
	</body>
	</html>
</xsl:template>

<!-- ================ head 要素テンプレ ================  -->

<xsl:template name="head">
	<head>
		<xsl:call-template name="head-meta"/>
		<meta name="ROBOTS" content="NOINDEX"/>
		<title><xsl:value-of select="$pageTitle"/></title>
		<xsl:call-template name="head-naviLink"/>
		<xsl:call-template name="head-metaLink"/>
		<xsl:call-template name="head-miscLink"/>
		<xsl:call-template name="head-css"/>
		<xsl:call-template name="head-script"/>
	</head>
</xsl:template>

<!-- ================ 見出しリスト抽出テンプレ ================  -->

<xsl:template name="extract-headings">
	<xsl:for-each select="document($fileList)/fl:dir/fl:dir[@name = $curDirName]/fl:dir[@name = $year]">
		<xsl:call-template name="everymonth">
			<xsl:with-param name="month" select="format-number(substring(fl:file[last()]/@name, 1, 2), '#0')"/>
		</xsl:call-template>
	</xsl:for-each>
</xsl:template>

<xsl:template name="everymonth">
	<xsl:param name="month"/>

	<xsl:if test="fl:file[substring(@name, 1, 2) = format-number($month, '00')]">
		<div id="m{format-number($month, '00')}" class="section">
			<h2>
				<xsl:value-of select="concat($year, '年', format-number($month, '00'), '月')"/>
			</h2>
			<ul>
				<xsl:for-each select="fl:file[substring(@name, 1, 2) = format-number($month, '00')]">
					<xsl:sort select="@name" order="descending"/>
					<xsl:call-template name="everyfile">
						<xsl:with-param name="currentfile" select="@name"/>
					</xsl:call-template>
				</xsl:for-each>
			</ul>
		</div>
	</xsl:if>

	<xsl:if test="$month &gt; 0">
		<xsl:call-template name="everymonth">
			<xsl:with-param name="month" select="$month - 1"/>
		</xsl:call-template>
	</xsl:if>

</xsl:template>

<xsl:template name="everyfile">
	<xsl:param name="currentfile"/>
	<xsl:for-each select="document(concat($nikkiDirFPath, $currentfile))/h:html/h:h3">
		<li>
			<span class="datetime">
				<xsl:text>(</xsl:text>
				<xsl:value-of select="js:n2DTF(substring-before(@s:datetime, 'T'))"/>
				<xsl:text>)</xsl:text>
			</span>
			<a href="{js:chsuffix(string($currentfile), 'html')}#{@id}">
				<xsl:apply-templates/>
			</a>
		</li>
	</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
