<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html [
 <!ENTITY Egrave "&#200;">
 <!ENTITY egrave "&#232;">
 <!ENTITY agrave "&#224;">
 <!ENTITY ugrave "&#249;">
 <!ENTITY nbsp "&#160;">
 <!ENTITY copy "&#0169;">
 <!ENTITY laquo "&#0171;">
 <!ENTITY raquo "&#0187;">
]>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" encoding="utf-8" indent="yes" />

  <xsl:param name="currpage" />
  <xsl:param name="language" />
  <xsl:param name="sortField" />
  <xsl:param name="sortOrder" />
  <xsl:param name="render_links">true</xsl:param>
  <xsl:param name="limit">1000</xsl:param>
  <xsl:param name="album"></xsl:param>

  <xsl:variable name="dataType">
   <xsl:choose>
    <xsl:when test="$sortField='id'">number</xsl:when>
    <xsl:otherwise>text</xsl:otherwise>
   </xsl:choose>
  </xsl:variable>

<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

<xsl:template match="/">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="music">
  <xsl:for-each select="album">
    <xsl:sort select="./*[local-name()=$sortField]" order="{$sortOrder}" data-type="{$dataType}" />

    <xsl:if test="($album = '') or (translate(title,' ABCDEFGHIJKLMNOPQRSTUVWXYZ','-abcdefghijklmnopqrstuvwxyz') = $album)">
      <div class="post">
         <h2 class="title"> <xsl:value-of select="title"/> (<xsl:value-of select=" substring(releasedate,0,5)"/>)</h2>
         <div class="entry">
           <xsl:choose>
             <xsl:when test="$language = 'it-IT'">
		   <p><img src="/_images/icon.zip.gif" style="margin-right: 5px;" alt="ZIP" /><a href="/music/{archive}">Scarica intero Album</a> compresso ZIP [<xsl:value-of select="archive/@size"/>]</p>
             </xsl:when>
             <xsl:otherwise>
		   <p><img src="/_images/icon.zip.gif" style="margin-right: 5px;" alt="ZIP" /><a href="/music/{archive}">Download Full Album</a> as ZIP archive [<xsl:value-of select="archive/@size"/>]</p>
             </xsl:otherwise>
           </xsl:choose>
           <xsl:apply-templates select="tracks"/>
		   <br/>
           <xsl:apply-templates select="covers"/>
         </div>
         <div class="meta">
            <p class="byline"><xsl:call-template name="render-date"><xsl:with-param name="date" select="releasedate"/></xsl:call-template>, Alessandro Polo</p>
            <p class="links"><a href="/music/{playlist}" class="more">M3U online playlist</a> <b>|</b> <a href="/music/{translate(title,' ABCDEFGHIJKLMNOPQRSTUVWXYZ','-abcdefghijklmnopqrstuvwxyz')}" class="comments"><xsl:choose>
             <xsl:when test="$language = 'it-IT'">apri album</xsl:when>
             <xsl:otherwise>open album</xsl:otherwise>
			</xsl:choose></a></p>
         </div>
      </div>
    </xsl:if>

  </xsl:for-each>
</xsl:template>


<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

<xsl:template match="tracks">
  <table class="wtable">
   <xsl:for-each select="track">
      <tr>
        <td class="tblfield" style="width: 30px;"><xsl:value-of select="number"/></td>
        <td class="tblfield" style="width: 40%; white-space: nowrap;"><a href="/music/{filename}"><xsl:value-of select="title"/></a></td>
        <td class="tblfield" style="width: 50%; white-space: nowrap;"><xsl:value-of select="length"/>'' [<xsl:value-of select="filename/@size"/>]</td>
        <td class="tblfield" style="width: 5%; white-space: nowrap; text-align: right;">
        <xsl:if test="./streampreview">
          <a href="?play={streampreview}" title="preview embedded "><img src="/_images/btn.play.png" alt="PLAY Online" /></a>
        </xsl:if>
          <a href="/music/{filename}" title="Download Track '{title}'"><img src="/_images/btn.download.png" alt="Download" /></a>
        </td>
      </tr>
   </xsl:for-each>
  </table>
</xsl:template>

<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

<xsl:template match="covers">

  <xsl:for-each select="cover">
      <a href="{.}"><img src="/music/{concat( substring-before(., '.jpg'), '_t.jpg')}" alt="{@type} cover" /></a>
  </xsl:for-each>
 
</xsl:template>

<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

<xsl:template name="render-date">
   <xsl:param name="date" />

   <xsl:if test="not (substring($date, 9, 1) = '0')">
    <xsl:value-of select="substring($date, 9, 1)" />
   </xsl:if>
   <xsl:value-of select="substring($date, 10, 1)" />
   <xsl:text> </xsl:text>

  <xsl:choose>
    <xsl:when test="$language = 'it-IT'">
      <xsl:choose>
        <xsl:when test="substring($date, 6, 2) = '01'">Gennaio</xsl:when>
        <xsl:when test="substring($date, 6, 2) = '02'">Febbraio</xsl:when>
        <xsl:when test="substring($date, 6, 2) = '03'">Marzo</xsl:when>
        <xsl:when test="substring($date, 6, 2) = '04'">Aprile</xsl:when>
        <xsl:when test="substring($date, 6, 2) = '05'">Maggio</xsl:when>
        <xsl:when test="substring($date, 6, 2) = '06'">Giugno</xsl:when>
        <xsl:when test="substring($date, 6, 2) = '07'">Luglio</xsl:when>
        <xsl:when test="substring($date, 6, 2) = '08'">Agosto</xsl:when>
        <xsl:when test="substring($date, 6, 2) = '09'">Settembre</xsl:when>
        <xsl:when test="substring($date, 6, 2) = '10'">Ottobre</xsl:when>
        <xsl:when test="substring($date, 6, 2) = '11'">Novembre</xsl:when>
        <xsl:when test="substring($date, 6, 2) = '12'">Dicembre</xsl:when>
      </xsl:choose>
    </xsl:when>
    <xsl:otherwise>
      <xsl:choose>
        <xsl:when test="substring($date, 6, 2) = '01'">January</xsl:when>
        <xsl:when test="substring($date, 6, 2) = '02'">February</xsl:when>
        <xsl:when test="substring($date, 6, 2) = '03'">March</xsl:when>
        <xsl:when test="substring($date, 6, 2) = '04'">April</xsl:when>
        <xsl:when test="substring($date, 6, 2) = '05'">May</xsl:when>
        <xsl:when test="substring($date, 6, 2) = '06'">June</xsl:when>
        <xsl:when test="substring($date, 6, 2) = '07'">July</xsl:when>
        <xsl:when test="substring($date, 6, 2) = '08'">August</xsl:when>
        <xsl:when test="substring($date, 6, 2) = '09'">September</xsl:when>
        <xsl:when test="substring($date, 6, 2) = '10'">October</xsl:when>
        <xsl:when test="substring($date, 6, 2) = '11'">November</xsl:when>
        <xsl:when test="substring($date, 6, 2) = '12'">December</xsl:when>
      </xsl:choose>
    </xsl:otherwise>
   </xsl:choose>

   <xsl:text> </xsl:text>
   <xsl:value-of select="substring($date, 1, 4)" />

</xsl:template>

<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

<xsl:template name="add-line-breaks">
   <xsl:param name="string" />

   <xsl:choose>
      <xsl:when test="contains($string, '&#xD;')">
         <xsl:value-of select="substring-before($string, '&#xD;')" />
         <br />
         <xsl:call-template name="add-line-breaks">
            <xsl:with-param name="string"
                            select="substring-after($string, '&#xD;')" />
         </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
         <xsl:value-of select="$string" />
      </xsl:otherwise>
   </xsl:choose>
</xsl:template>

<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

<xsl:template match="anchor">
  <a name="{.}">&nbsp;<xsl:text> </xsl:text></a>
</xsl:template>

<xsl:template match="para">
  <xsl:element name="p">
    <xsl:for-each select="@*">
      <xsl:attribute name="{name()}"><xsl:value-of select="."/></xsl:attribute>
    </xsl:for-each>
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>


<xsl:template match="unorderedlist">
  <ul>
    <xsl:for-each select="listitem">
       <li><xsl:apply-templates /></li>
    </xsl:for-each>
  </ul>
</xsl:template>


<xsl:template match="li">
   <xsl:apply-templates />
</xsl:template>


<xsl:template match="@*|a|img|br|i" priority="-1">
  <xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:template>


</xsl:stylesheet>

