<?xml version="1.0"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" omit-xml-declaration="yes" indent="no" encoding="ISO-8859-1"/>

<xsl:variable name="englishdb" select="document('../db/lfdb.en.xml')"/>
<xsl:variable name="localdb" select="document('../db/lfdb.nl.xml')"/>

<xsl:variable name="version" select="'0.1'"/>
<xsl:variable name="stylesheetname" select="'theme-db.xslt'"/>
<xsl:variable name="lfroot" select="''"/>

<xsl:template match="/">
 
      <xsl:for-each select="$englishdb/database/issues/issue">
        <xsl:sort select="@code" data-type="number" order="ascending"/>
        <xsl:if test="published">
          <xsl:apply-templates select="."/>
        </xsl:if>
      </xsl:for-each>

</xsl:template>

<xsl:template match="issue">
  <xsl:variable name="issueid"><xsl:value-of select="@id"/></xsl:variable>

  <xsl:text>
#</xsl:text>
  <xsl:value-of select="$englishdb/database/issues/issue[@id=$issueid]/title"/>
  <xsl:text>
</xsl:text>
  <xsl:for-each select="$englishdb/database/articles/article/issueref[@href=$issueid]">
    <xsl:sort select="@id" data-type="number" order="ascending"/>
    <xsl:variable name="id" select="@id"/>
    <xsl:apply-templates select="..">
        <xsl:with-param name="issueid" select="$issueid"/>
    </xsl:apply-templates>
  </xsl:for-each>
</xsl:template>

<xsl:template match="article">
  <xsl:param name="issueid"/>
  <xsl:variable name="artid"><xsl:value-of select="@id"/></xsl:variable>
  <xsl:variable name="artlang"><xsl:value-of select="$englishdb/database/articles/article[@id=$artid]/@xml:lang"/></xsl:variable>
  <xsl:variable name="article" select="$localdb/database/articles/article[@id=$artid]"/>
      <xsl:choose>
        <xsl:when test="substring(@id,1,3)='cov'">
	<!-- It's a cover ; do nothing -->
        </xsl:when>
        <xsl:when test="$article/translation/finished or $artlang='nl'">
          <xsl:choose>
            <xsl:when test="not(nohtml)">
                <xsl:choose>
                  <xsl:when test="normalize-space($article/title[@xml:lang='nl'])">
                    <xsl:value-of select="substring($artid,8,10)"/>
		    <xsl:text> ::: </xsl:text>
                    <xsl:value-of select="$article/title[@xml:lang='nl']"/>
		    <xsl:text> ::: </xsl:text>
                    <xsl:value-of select="normalize-space($article/abstract[@xml:lang='nl'])"/>
		    <xsl:text>
</xsl:text>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="substring($artid,8,10)"/>
		    <xsl:text> ::: </xsl:text>
                    <xsl:value-of select="title"/>
		    <xsl:text> ::: 
</xsl:text>
                  </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise><xsl:value-of select="$article/title"/></xsl:otherwise>
          </xsl:choose>
        </xsl:when>
        <xsl:otherwise>
	  <!-- article not in NL -->
          <xsl:value-of select="substring($artid,8,10)"/>
	  <xsl:text> ::: </xsl:text>
          <xsl:value-of select="title"/>
	  <xsl:text> ::: 
</xsl:text>
        </xsl:otherwise>        
      </xsl:choose>

</xsl:template>

</xsl:stylesheet>
