<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
		xmlns="http://www.w3.org/1999/xhtml"
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		extension-element-prefixes="exsl"
		xmlns:exsl="http://exslt.org/common"> 
  
  <xsl:output method="xml" version="1.0" encoding="iso-8859-1"
	      standalone="yes" indent="yes"
	      doctype-public="-//W3C//DTD XHTML 1.1//EN"
	      doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"/>
  
  <xsl:include href="misc.xsl"/>
  
  <xsl:template match="set">
    <html xml:lang="sv">
      <head>
        <title>Rasmus Fantomenindex: Biserier</title>
        <xsl:call-template name="baselinks"/>
        <script type="text/javascript" src="{$base}sortable.js">&#160;</script>
      </head>
    
      <body>
	<xsl:call-template name="topstuff"/>
        <div class="prematter">
	<h1>Biserier i Fantomen</h1>
	
	<div class="main text">
          <p>Här listas de olika serier som har gått i den svenska
          Fantomen&#xAD;tidningen, sorterade på första förekomst (i de
          tidningar jag har indexerat).</p>
          
          <p>Siffrorna till höger är ett försök att åskådliggöra vilka år
          respektive serie har förekommit.</p>
        </div>
	</div>
        <div class="main">
          
	<div class="block" id="slist">
	<h2>Serier</h2>
        <table class="sortable" id="serier">
          <thead>
            <tr>
              <th>Serie</th>
              <th>Först</th>
              <th>Senast</th>
              <th title="Antal indexerade förekomster (inkl. repriser)">n</th>
              <xsl:for-each select="document('yset.xml')//year">
                <xsl:variable name="dec"
                              select="substring(., 1, 3)"/>
                <xsl:if test="not(preceding-sibling::year[substring(.,1,3)= $dec])">
                  <th class="decade d{$dec} unsortable">
                    <xsl:value-of select="$dec"/>x
                  </th>
                </xsl:if>
              </xsl:for-each>
              <th class="xx unsortable"></th>
            </tr>
          </thead>
          <tbody id="huser">
	  <xsl:for-each select="serie[not(. = preceding-sibling::serie)]">
	    <xsl:variable name="serie" select="."/>
	    <xsl:variable name="id" select="translate(., $badc1, $badc2)"/>
	    
            <tr>
              <td>
                <a class="xref" href="{$id}.html"><xsl:value-of
                select="."/></a>
              </td>
              
              <td><xsl:value-of select="@i"/></td>
              <td>
                <xsl:choose>
                  <xsl:when test="following-sibling::serie[.=$serie]">
                    <xsl:value-of
                        select="following-sibling::serie[.=$serie][last()]/@i"/>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="@i"/>
                  </xsl:otherwise>
                </xsl:choose>
              </td>
              <td style="text-align: right;">
                <xsl:value-of 
                    select="1+count(following-sibling::serie[.=$serie])"/>
              </td>
              
              <xsl:for-each select="document('yset.xml')//year">
                <xsl:variable name="dec"
                              select="substring(., 1, 3)"/>
                <xsl:if test="not(preceding-sibling::year[substring(.,1,3)= $dec])">
                  <td class="decade d{$dec}" title="{$dec}x">
                    <xsl:apply-templates select="document('yset.xml')//year[substring(.,1,3)= $dec]"
                                         mode="ifdata">
                      <xsl:with-param name="serie" select="$serie"/>
                    </xsl:apply-templates>
                  </td>
                </xsl:if>
              </xsl:for-each>
            </tr>
	    <xsl:choose>
	      <xsl:when test="element-available('exsl:document')">
		<xsl:message>Writing <xsl:value-of select="$id"/>.html</xsl:message>
		<exsl:document href="{$id}.html" method="xml" indent="yes"
			       encoding="iso-8859-1" standalone="yes"
			       doctype-public="-//W3C//DTD XHTML 1.1//EN"
			       doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
		  <html xml:lang="sv">
                    <head>
                      <title>
                        <xsl:value-of select="$serie"/>
                        <xsl:text> i Rasmus Fantomenindex</xsl:text>
                      </title>
                      <xsl:call-template name="baselinks"/>
                      <link rel="Up" href="titles"/>
                    </head>
                    <body id="t{$id}">
		      <xsl:call-template name="topstuff"/>
                      <div class="prematter">
		      <h1><xsl:value-of select="$serie"/></h1>

		      <div class="main">
			<!-- TODO: Mer info här! -->
                        <p>
                          <xsl:text>Här listas de gånger serien </xsl:text>
                          <xsl:call-template name="lookup">
                            <xsl:with-param name="term" select="$serie"/>
                          </xsl:call-template>
                          <xsl:text> förekommer i mina indexerade
                          fantomentidningar.</xsl:text>
                        </p>
                        <xsl:apply-templates
                            select="document('yset.xml')//year"
                            mode="ref">
                          <xsl:with-param name="serie" select="$serie"/>
                        </xsl:apply-templates>
		      </div>
		      </div>
                      
		      <div class="main">
		      <xsl:apply-templates select="document('yset.xml')//year"
					   mode="serie">
			<xsl:with-param name="serie" select="$serie"/>
			<xsl:with-param name="id" select="$id"/>
		      </xsl:apply-templates>
		      </div>
		      <xsl:call-template name="trailer"/>
		    </body>
		  </html>
		</exsl:document>
	      </xsl:when>
	      <xsl:otherwise>
		<xsl:message>exsl:document saknas</xsl:message>
	      </xsl:otherwise>
	    </xsl:choose>
	  </xsl:for-each>
          </tbody>
	</table>
	<hr class="sep"/>
        </div>
	</div>
	
	<xsl:call-template name="trailer"/>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="yset">
    <h2>Årgångar</h2>

    <ul>
      <xsl:for-each select="year">
	<li>
	  <xsl:if test="not(starts-with(preceding-sibling::year[1], substring(., 1, 3)))">
	    <xsl:attribute name="class">newdecade</xsl:attribute>
	  </xsl:if>
	  <a class="xref" href="{.}.html"><xsl:apply-templates/></a>
	</li>
        <xsl:text>&#10;      </xsl:text>
      </xsl:for-each>
    </ul>
  </xsl:template>

  <xsl:template match="year" mode="serie">
    <xsl:param name="serie"/>
    <xsl:param name="id"/>
    <xsl:variable name="x"
		  select="document(concat(., '.data'))
			 //serie[title=$serie]"/>
    
    <xsl:if test="$x">
      <div class="year">
	<h2><a href="{.}.html" class="xref"><xsl:apply-templates/></a></h2>

	<xsl:apply-templates select="$x"/>
        <hr/>
      </div>
    </xsl:if>
  </xsl:template>

  <xsl:template match="year" mode="ref">
    <xsl:param name="serie"/>
    <xsl:variable name="year" select="."/>
    
    <xsl:for-each  select="document(concat($year, '.data'))
                          //text[ref/serie=$serie]">
      <p>
        <xsl:text>Se även </xsl:text>
        <xsl:value-of select="title"/>
        <xsl:text> i </xsl:text>
        <a href="{$base}{$year}#i{parent::issue/@nr}" class="xref">
          <xsl:text>nr </xsl:text>
          <xsl:value-of select="parent::issue/@nr"/>,
          <xsl:value-of select="$year"/>
        </a>
        <xsl:if test="subtitle">
          <xsl:text>: </xsl:text>
          <xsl:value-of select="subtitle"/>
        </xsl:if>
        <xsl:text>.</xsl:text>
      </p>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="year" mode="ifdata">
    <xsl:param name="serie"/>
    <xsl:variable name="year" select="."/>
    <xsl:choose>
      <xsl:when test="document(concat($year, '.data'))//serie[title=$serie]">
        <span title="{$year}" class="y">
        <xsl:value-of select="substring($year, 4, 1)"/></span>
      </xsl:when>
      <xsl:otherwise><span class="n">&#160;</span></xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  
  <xsl:template match="serie">
    <div class="serie">
      <h3>
      <xsl:text>#</xsl:text>
      <xsl:value-of select="parent::issue/@nr"/>
        <xsl:apply-templates mode="serieheadline"
                             select="label|episode[1]|part"/>
        <xsl:apply-templates mode="serieheadline" select="best"/>
      </h3>
      
      <xsl:call-template name="details"/>
    </div>
  </xsl:template>
</xsl:stylesheet>

