<?xml version="1.0" encoding="EUC-JP"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns="http://www.w3.org/TR/REC-html40"
	xmlns:d="http://www.horobi.com/xmlns/diary"
	xmlns:log="http://www.horobi.com/xmlns/log"
	xmlns:b="http://www.horobi.com/xmlns/bib"
	xmlns:nav="http://www.horobi.com/xmlns/navigation"
	xmlns:l="http://www.horobi.com/xmlns/link"
	xmlns:n="http://www.horobi.com/xmlns/note"
	xmlns:e="http://www.horobi.com/xmlns/event"
	>
<xsl:output method="html" encoding="EUC-JP"/>

<xsl:key name="bib" match="b:author"
         use="translate(./text(),' &#x09;&#x0a;','')"/>


<xsl:template match="/">
  <html>
    <head><title>作家索引</title></head>
    <body bgcolor="#eeeecc">
      <table width="100%">
        <tr>
	  <td valign="bottom">
	    <a href="dindex.html">[一覧]</a><xsl:text> </xsl:text>
	    <a href="dindex-bib.html">[書籍索引]</a><xsl:text> </xsl:text>
	    [作家索引]<xsl:text> </xsl:text>
	    <!--<a href="dindex-link.html">[リンク索引]</a><xsl:text> </xsl:text>-->
	  </td>
	  <td valign="bottom">
	    <font size="-2">
	    ※1999年4月以前の日記はインデックス化していません。<br />
	    ※言及されていても索引に出てこない場合もあります(宮台氏等)。
	    </font>
	  </td>
	  <td valign="top">
            <h1 align="right">
	      <font color="#5555cc">作家索引</font>
	    </h1>
	  </td>
        </tr>
      </table>
      <hr />
      <xsl:apply-templates select="//b:author" mode="toc">
        <xsl:sort select="." />
      </xsl:apply-templates>
      <hr />
      <xsl:apply-templates select="//b:author">
        <xsl:sort select="." />
      </xsl:apply-templates>
    </body>
  </html>
</xsl:template>

<xsl:template match="b:author" mode="toc">
  <xsl:variable name="author" select="translate(./text(),' &#x09;&#x0a;','')"/>
  <xsl:if test="generate-id(key('bib',$author)[position()=1])=generate-id(.)">
    <xsl:if test="position()!=1"> / </xsl:if>
    <a href="#{generate-id()}"><font color="##0055cc"><xsl:value-of select="."/></font></a>
  </xsl:if>
</xsl:template>

<xsl:template match="b:author">
  <xsl:variable name="author" select="translate(./text(),' &#x09;&#x0a;','')"/>
  <xsl:if test="generate-id(key('bib',$author)[position()=1])=generate-id(.)">
    <p>
      <a name="{generate-id(.)}">
        <b><font color="##0055cc"><xsl:value-of select="."/></font>:</b>
      </a>
      <xsl:apply-templates select="key('bib',$author)/ancestor::log:log">
        <xsl:sort select="../@year"
              data-type="number" order="ascending" />
        <xsl:sort select="substring-before(@date,'-')"
              data-type="number" order="ascending" />
	<xsl:sort select="substring-after(@date,'-')"
              data-type="number" order="ascending" />
      </xsl:apply-templates>
    </p>
  </xsl:if>
</xsl:template>

<!-- -->
<xsl:template match="log:log">
  <xsl:variable name="file" select="ancestor::file/@name"/>
  <xsl:if test="position()!=1"> / </xsl:if>
  <a href="{$file}.html#{@date}" target="diary">
    <font size="-2" color="#aa0000">
      <b>[<xsl:value-of select="../@year"/>-<xsl:value-of select="@date"/>] </b>
    </font>
    <xsl:choose>
      <xsl:when test="log:sub">
        <xsl:apply-templates select="log:sub"/>
      </xsl:when>
      <xsl:when test="d:section">
        <font size="-1" color="#5555cc">
        <xsl:apply-templates select="d:section/d:subject"/>
	</font>
      </xsl:when>
      <xsl:otherwise>
      </xsl:otherwise>
    </xsl:choose>
  </a>
</xsl:template>

<xsl:template match="d:subject">
  <xsl:value-of select="."/>
  <xsl:if test="position()!=last()">/</xsl:if>
</xsl:template>

<xsl:template match="log:sub">
  <font size="-1" color="#5555cc">
    <xsl:value-of select="."/>
  </font>
</xsl:template>

<xsl:template match="log:sub[normalize-space(.)='']">
  <font color="gray" size="-1">(無題)</font>
</xsl:template>

</xsl:stylesheet>
