<?xml version="1.0" encoding="UTF-8"?>

<!-- 日記ジャンル分け定義 XML にジャンル毎の記事件数データを付与 -->

<xsl:stylesheet version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns="http://www.remus.dti.ne.jp/~a-satomi/nikki-genres"
	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:ng="http://www.remus.dti.ne.jp/~a-satomi/nikki-genres"
	xmlns:xalan="http://xml.apache.org/xalan"
	exclude-result-prefixes="h s js fl ng xalan">

<xsl:import href="common.xsl"/>

<!-- ================ 出力設定 ================  -->

<xsl:output method="xml"
	encoding="UTF-8"
	omit-xml-declaration="no"
	indent="yes"
	xalan:indent-amount="2"
	media-type="application/xhtml+xml"/>

<!-- ================ 各種設定 ================  -->

<xsl:param name="genreDirFPath" select="concat($baseDir, '/nikki/genres/')"/>

<!-- ================ テンプレ ================  -->

<xsl:template match="/">
	<xsl:apply-templates select="ng:genres"/>
</xsl:template>

<xsl:template match="ng:genre">
	<xsl:param name="articleIndex" select="concat($genreDirFPath, @name, '.html')"/>
	<xsl:param name="count" select="count(document($articleIndex)/h:html/h:body/h:div/h:div/h:ul/h:li)"/>
	<xsl:copy>
		<xsl:attribute name="count"><xsl:value-of select="$count"/></xsl:attribute>
		<xsl:apply-templates select="@*|node()" />
	</xsl:copy>
</xsl:template>

<xsl:template match="@*|node()" priority="-5.0">
	<xsl:copy>
		<xsl:apply-templates select="@*|node()" />
	</xsl:copy>
</xsl:template>

</xsl:stylesheet>
