<?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:xalan="http://xml.apache.org/xalan"
	exclude-result-prefixes="h s js xalan">

<xsl:import href="gallery.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="cssTitle">だーくすとらいぷ</xsl:param>
<xsl:param name="darkMode" select="true()"/>

<!-- ================ メインテンプレ ================  -->

<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-dark"/>
		<xsl:apply-templates select="h:h1"/>
		<xsl:call-template name="navi-dark"/>
		<xsl:call-template name="footer-dark"/>
	</body>
	</html>
</xsl:template>

<!-- ================ ナビリンク・フッタ変更 ================  -->
<!--
　img src の common/img/ → common/img/dark/ 変換
-->

<xsl:template name="navi-dark">
	<xsl:param name="navi">
		<xsl:call-template name="navi"/>
	</xsl:param>
	<xsl:apply-templates select="xalan:nodeset($navi)" mode="dark"/>
</xsl:template>

<xsl:template name="footer-dark">
	<xsl:param name="footer">
		<xsl:call-template name="footer"/>
	</xsl:param>
	<xsl:apply-templates select="xalan:nodeset($footer)" mode="dark"/>
</xsl:template>

<!-- ========== ナビリンク・フッタ用 / xalan:nodeset() 内ノード処理 ==========  -->

<xsl:template match="h:*" mode="dark" priority="-5.0">
	<xsl:element name="{local-name()}">
		<xsl:apply-templates select="node() | @*" mode="dark"/>
	</xsl:element>
</xsl:template>

<xsl:template match="@*" mode="dark" priority="-5.0">
	<xsl:copy/>
</xsl:template>

<xsl:template match="text()[js:match(string(self::node()), '/&lt;\/?script/')]" mode="dark">
	<xsl:value-of select="self::node()" disable-output-escaping="yes"/>
</xsl:template>

<xsl:template match="text()[contains(self::node(), '&amp;copy')]" mode="dark">
	<xsl:value-of select="js:replace(string(self::node()), '/&amp;copy;/g', '&#169;')"/>
</xsl:template>

<xsl:template match="h:li[@id = 'dMomo']" mode="dark"/>

<xsl:template match="h:img/@src[contains(self::node(), '/common/img/')]" mode="dark">
	<xsl:attribute name="src">
		<xsl:value-of select="js:replace(string(self::node()), '/(\/common\/img\/)/', '$1dark/')"/>
	</xsl:attribute>
</xsl:template>

<!-- ================ p 要素変更 ================  -->

<!-- h1 従属の p 要素 (stair.xml only) -->
<xsl:template match="h:p[/h:html/h:h1/@id = 'stair']">
	<p>
		<xsl:apply-templates select="@*"/>
		<xsl:attribute name="id">
			<xsl:value-of select="concat('p', count(preceding-sibling::h:p) + 1)"/>
		</xsl:attribute>
		<xsl:apply-templates/>
	</p>
</xsl:template>

<!-- ============ s:notice (注意事項生成) ============  -->

<xsl:template match="s:notice">
	<xsl:for-each select="document(concat($baseDir, '/', $curDirName, '/door.xml'))/h:html">
		<div class="section">
			<xsl:apply-templates select="h:h2[last()]" mode="notice"/>
			<ul>
				<xsl:apply-templates select="h:h2[last()]/following-sibling::h:ul[1]/h:li[position() &gt; 1]"/>
				<li>
					<form enctype="application/x-www-form-urlencoded" action="%action%" method="post">
						<p>
							<input value="exit" name="mode" type="hidden" />
							<input value="会員証返却" type="submit" />
							<xsl:text>クッキーを消去します。</xsl:text>
						</p>
					</form>
				</li>
			</ul>
		</div>
	</xsl:for-each>
</xsl:template>

<xsl:template match="h:h2" mode="notice">
	<h2>
		<xsl:apply-templates select="node() | @*"/>
	</h2>
</xsl:template>

<!-- ============== input type="checkbox" 変更 ===============  -->

<xsl:template match="h:input[@type = 'checkbox']">
	<xsl:text disable-output-escaping="yes">&lt;input</xsl:text>
	<xsl:for-each select="@*">
		<xsl:text> </xsl:text>
		<xsl:value-of select="name()"/>
		<xsl:text>=&quot;</xsl:text>
		<xsl:value-of select="self::node()"/>
		<xsl:text>&quot;</xsl:text>
	</xsl:for-each>
	<xsl:text disable-output-escaping="yes"> class="checkbox"%checked% /&gt;</xsl:text>
</xsl:template>


</xsl:stylesheet>
