歳時記を書換える
同一ページにある<a>タグに同一テキストノードを指定する場合はtitle属性をつけて区別したほうが良いようです.歳時記をAnother HTML-lintでチェックしたら山のように減点となりました.要するに,
<!--saijiki/index.xml-->
<root>
<head/>
<body>
<h1>歳時記</h1>
<table border="1" class="Calendar">
<tr><th>1月</th>
<td><a href="01/0101.html">01</a></td>
<td><a href="01/0102.html">02</a></td>
<td><a href="01/0103.html">03</a></td>
・
・
・
</tr>
<tr><th>2月</th>
<td><a href="02/0201.html">01</a></td>
<td><a href="02/0202.html">02</a></td>
<td><a href="02/0203.html">03</a></td>
・
・
・
</tr>
</table>
</body>
</root>
こう書くと,各月の各日が同じ名前なのでダブっているというわけです.この場合は一意なtitle属性を指定するようです.つまり,こうなります.
<!--saijiki/index.xml-->
<root>
<head/>
<body>
<h1>歳時記</h1>
<table border="1" class="Calendar">
<tr><th>1月</th>
<td><a href="01/0101.html" title="0101">01</a></td>
<td><a href="01/0102.html" title="0102">02</a></td>
<td><a href="01/0103.html" title="0103">03</a></td>
・
・
・
</tr>
<tr><th>2月</th>
<td><a href="02/0201.html" title="0201">01</a></td>
<td><a href="02/0202.html" title="0202">02</a></td>
<td><a href="02/0203.html" title="0203">03</a></td>
・
・
・
</tr>
</table>
</body>
</root>
xmlファイルを置換しても良いのですが,芸がありません.そこで,title属性はxslで付け加えることにしました.歳時記はファイル名を年と月から機械的に決めることができるので,ついでにファイル名称もxslの中で決めることにします.
xmlファイルに<calendar>,<month>,<day>と三つのタグを新設します.<table>で書いていた部分を以下のように書換えます.
<!--saijiki/index.xml-->
<root>
<head/>
<body>
<h1>歳時記</h1>
<calendar>
<month mon="01">1月
<day>01</day>
<day>02</day>
<day>03</day>
・
・
・
</month>
<month mon="02">2月
<day>01</day>
<day>02</day>
<day>03</day>
・
・
・
</month>
</calendar>
</body>
</root>
これをxhtmlに変換するxslは以下の通りです.
<--saijiki.xsl--> <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:include href="framework.xsl"/> <xsl:template name="stylesheet"> <link rel="stylesheet" title="Recommends" type="text/css" href="../css.css"/> <link rel="start" href="../index.html"/> <link rel="contents" href="../index.html"/> <link rel="prev" href="../whatsnew/index.html"/> <link rel="next" href="../ryokoki/index.html"/> </xsl:template> <xsl:template name="Menu"> <div class="Menu"> <a href="../index.html">眠る猫の頁</a><xsl:call-template name="menu_hie"/> <xsl:value-of select="h1"/><br /> <a href="../index.html">表紙</a><xsl:call-template name="menu_div"/> <a href="../whatsnew/index.html">新着</a><xsl:call-template name="menu_div"/>歳時記<xsl:call-template name="menu_div"/> <a href="../ryokoki/index.html">旅行記</a><xsl:call-template name="menu_div"/> <a href="../hyoryuki/index.html">漂流記</a><xsl:call-template name="menu_div"/> <a href="../biboroku/index.html">備忘録</a><xsl:call-template name="menu_div"/> <a href="../zatsuroku/index.html">雑録</a><xsl:call-template name="menu_div"/> <a href="../links/index.html">リンク</a> </div> </xsl:template> <xsl:template match="body"> <body> <xsl:call-template name="Menu"/> <xsl:copy-of select="h1"/> <xsl:apply-templates select="calendar"/> <hr /> <div class="MailTo"> ご意見・ご感想は<a href="mailto:foo@bar">foo@bar</a>まで. </div> <xsl:call-template name="AccessLog"/> </body> </xsl:template> <xsl:template match="calendar"> <!--calendarタグが出現したらテーブルに変換--> <table border="1" class="Calendar"> <xsl:apply-templates/> </table> </xsl:template> <xsl:template match="month"> <tr><th><xsl:value-of select="text()"/></th> <xsl:apply-templates select="day"/> </tr> </xsl:template> <xsl:template match="day"> <xsl:variable name="month" select="../@mon"/> <td> <xsl:if test="@new[.='true']"> <!--<day new="true">とnew属性を指定すると赤太字のNewを表示--> <span class="New">New</span> </xsl:if> <a href="{concat($month,'/',$month,.,'.html')}" title="{concat($month,.)}"> <xsl:value-of select="."/> </a> </td> </xsl:template> <xsl:template name="AccessLog"> <div class="AccessLog"> <script type="text/javascript" src="saijiki.js"/> <img width="1" height="1" src="/cgi-bin/user/sasa/aclogsIMG.cgi?saijiki" alt=""/> </div> </xsl:template> </xsl:stylesheet>
<--framework.xsl--> <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" encoding="UTF-8" indent="no" doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"/> <xsl:template name="stylesheet"> <!--各ページに対応したXSLTで実装--> </xsl:template> <xsl:template name="Menu"> <!--各ページに対応したXSLTで実装--> </xsl:template> <xsl:template name="AccessLog"> <!--各ページに対応したXSLTで実装--> </xsl:template> <xsl:template match="root"> <html > <xsl:apply-templates select="head"/> <xsl:apply-templates select="body"/> </html> </xsl:template> <xsl:template match="head"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <meta http-equiv="Content-Script-Type" content="text/javascript"/> <xsl:apply-templates select="meta"/> <xsl:call-template name="stylesheet"/> <link rev="made" href="mailto:foo@bar"/> <title><xsl:value-of select="/root/body/h1"/></title> </head> </xsl:template> <xsl:template match="body"> <body> <xsl:call-template name="Menu"/> <xsl:copy-of select="*"/> <!--マッチしたタグ自身を含まない--> <hr /> <div class="MailTo"> ご意見・ご感想は<a href="mailto:foo@bar">foo@bar</a>まで. </div> <xsl:call-template name="AccessLog"/> </body> </xsl:template> <xsl:template match="meta"> <xsl:copy-of select="."/> <!--マッチしたタグ自身を含む--> </xsl:template> <xsl:template name="nbsp"> <xsl:text disable-output-escaping="yes"> </xsl:text> </xsl:template> <xsl:template name="menu_div"> <xsl:text disable-output-escaping="yes"> | </xsl:text> </xsl:template> <xsl:template name="menu_hie"> <xsl:text disable-output-escaping="yes"> > </xsl:text> </xsl:template> </xsl:stylesheet>