<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--  $Id$  -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:dyn="http://exslt.org/dynamic" extension-element-prefixes="dyn">
  <xsl:output method="html" indent="no" doctype-system="http://www.w3.org/TR/html4/strict.dtd" doctype-public="-//W3C//DTD HTML 4.01//EN" encoding="utf-8" />
      


  <xsl:template match="Root">
    <div class="section">
	
	    <TABLE class="textChart">
	       <TR>
	         <TH class="catalogCol">Catalog</TH>
	         <TH class="titleCol">Title</TH>
	         <TH class="albumArtistCol">Artist</TH>
	         <TH class="trackCountCol alignCenter">Tracks</TH>
	         <TH class="albumID">Album ID</TH>
	       </TR>
	
	       <xsl:for-each select="Distribution/Albums/Album">
	         <xsl:variable name="row">
	           <xsl:choose>
	             <xsl:when test="position() mod 2 = 1">row1</xsl:when>
	             <xsl:otherwise>row0</xsl:otherwise>
	           </xsl:choose>
	         </xsl:variable>
	         
	         <tr class="{$row}">
	           <xsl:call-template name="displayAlbum" />
	         </tr>
	         
	         <xsl:if test="count(Tracks/Track)">
	           <TR class="{$row}">
	             <TD colspan="5">
	               <TABLE class="textChart">
	                 
	                 <TR>
	                   <TH class="trackPadCol"><xsl:text> </xsl:text></TH>
	                   <TH class="discCol alignCenter">Disc</TH>
	                   <TH class="trackCol alignCenter">Track</TH>
	                   <TH class="trackTitleCol">Title</TH>
	                   <TH class="trackArtist">Artist</TH>
	                   <TH class="trackISRC">ISRC</TH>
	                   <TH class="trackID">ID</TH>
	                 </TR>
	                 
	                 <xsl:for-each select="Tracks/Track">
	                   <TR>
	                     <xsl:call-template name="displayTrack" />
	                   </TR>
	                 </xsl:for-each>
	
	               </TABLE>
	             </TD>
	           </TR>
	         </xsl:if>
	           
	       </xsl:for-each>         
	    </TABLE>
    </div>
    <br />
  </xsl:template>
    
  <xsl:template name="displayAlbum">
    <xsl:call-template name="tableDataItem">
      <xsl:with-param name="value" select="catalog_no" />
    </xsl:call-template>
    
    <xsl:call-template name="tableDataItem">
      <xsl:with-param name="value" select="album_title" />
      <xsl:with-param name="width" select="'45'" />
    </xsl:call-template>
    
    <xsl:call-template name="tableDataItem">
      <xsl:with-param name="value" select="album_artist" />
      <xsl:with-param name="width" select="'20'" />
    </xsl:call-template>
    
    <xsl:call-template name="tableDataItem">
      <xsl:with-param name="value" select="track_count" />
      <xsl:with-param name="class" select="'alignCenter'" />
    </xsl:call-template>
    
    <xsl:call-template name="tableDataItem">
      <xsl:with-param name="value" select="client_album_id" />
      <xsl:with-param name="width" select="'15'" />
    </xsl:call-template>
  </xsl:template>
  

  <xsl:template name="displayTrack">
    <TD></TD>
    <xsl:call-template name="tableDataItem">
      <xsl:with-param name="value" select="disc_no" />
      <xsl:with-param name="class" select="'alignCenter'" />
    </xsl:call-template>

    <xsl:call-template name="tableDataItem">
      <xsl:with-param name="value" select="track_number" />
      <xsl:with-param name="class" select="'alignCenter'" />
    </xsl:call-template>

    <xsl:call-template name="tableDataItem">
      <xsl:with-param name="value" select="track_title" />
      <xsl:with-param name="width" select="'35'" />
    </xsl:call-template>

    <xsl:call-template name="tableDataItem">
      <xsl:with-param name="value" select="track_artist" />
      <xsl:with-param name="width" select="'20'" />
    </xsl:call-template>

    <xsl:call-template name="tableDataItem">
      <xsl:with-param name="value" select="isrc" />
    </xsl:call-template>

    <xsl:call-template name="tableDataItem">
      <xsl:with-param name="value" select="client_track_id" />
      <xsl:with-param name="width" select="'10'" />
    </xsl:call-template>
  </xsl:template>


  <xsl:template name="tableDataItem">
    <xsl:param name="message" />
    <xsl:param name="status" />
    <xsl:param name="value" />    
    <xsl:param name="class" />    
    <xsl:param name="width" />    
    
    <xsl:variable name="errorClass">
      <xsl:if test="$status"> errorInput</xsl:if>
    </xsl:variable>

    <xsl:variable name="cellData">
      <xsl:choose>
        <xsl:when test="$width">
          <xsl:call-template name="truncateString">
            <xsl:with-param name="string" select="$value" />
            <xsl:with-param name="width"  select="$width" />
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$value" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:variable name="title">
      <xsl:choose>
        <xsl:when test="$status and not ($status = 7 or $status = 8)">
          <xsl:value-of select="$message" />
        </xsl:when>
        <xsl:when test="string-length($cellData) != string-length($value)">
          <xsl:value-of select="$value" />
        </xsl:when>
      </xsl:choose>
    </xsl:variable>
    
    <TD title="{$title}" class="{$class}{$errorClass}">
      <xsl:value-of select="$cellData" />
    </TD>
  </xsl:template>
  
  <xsl:template name="truncateString">
    <xsl:param name="string" />
    <xsl:param name="width" />
    
    <xsl:choose>
      <xsl:when test="string-length($string) &gt; $width - 3">
        <xsl:value-of select="substring( $string, 1, $width - 3 )" />...
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$string" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  
</xsl:stylesheet>

