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

  <xsl:template name="pieChart">
    <div class="pieChart{$chartPosition}">
      <xsl:if test="normalize-space($chartTitle)">
        <h2><a href="?c={$chartAction}&amp;period={$period}&amp;label_id={$labelId}"><xsl:value-of select="$chartTitle" /></a></h2>
      </xsl:if>
      <map name="{chart_name}" id="{chart_name}">
        <xsl:value-of select="image_map" disable-output-escaping="yes" />
      </map>
      <table class="pieChartTable">
        <tr>
          <td class="pieChartTD"><img src="/test/images/temp/pieOnly2.gif" alt="Chart of {$chartTitle}" usemap="#{chart_name}" class="pieChartImage" /></td>
          <td class="pieLegendTD">
            <div class="pieLegend">
              <div><a href="#"><img src="/test/images/legendColor.gif" class="legend1" /> 58% - iTunes</a></div>
              <div><a href="#"><img src="/test/images/legendColor.gif" class="legend2" /> 11% - Napster</a></div>
              <div><a href="#"><img src="/test/images/legendColor.gif" class="legend3" /> 9% - iTunes Europe</a></div>
            </div>
          </td>
        </tr>
      </table>
    </div>
  </xsl:template>

  <xsl:template name="salesChart">
    <div class="textChart{$chartPosition}">
      <xsl:if test="normalize-space($chartTitle)">
        <h2><a href="?c={$chartAction}&amp;period={$period}&amp;label_id={$labelId}"><xsl:value-of select="$chartTitle" /></a></h2>
      </xsl:if>
      <table>
        <xsl:apply-templates select="header_row" />
        <xsl:for-each select="data_row">
          <xsl:call-template name="salesRow">
            <xsl:with-param name="chartAction"><xsl:value-of select="substring($chartAction,1,1)"/></xsl:with-param>
            <xsl:with-param name="chartType"><xsl:value-of select="$chartType" /></xsl:with-param>
          </xsl:call-template>
        </xsl:for-each>
      </table>
    </div>
  </xsl:template>

  <xsl:template name="statusChart">
    <div class="sectionHeader"><h1>Sales Data Status</h1></div>
    <div class="sectionWrap">
      <div class="sectionBody">
        <table id="statusChart">
          <xsl:apply-templates select="header_row" />
          <xsl:for-each select="data_row">
            <xsl:sort select="translate(cell[1]/value,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />
            <xsl:call-template name="statusRow" />
        </xsl:for-each>
        </table>
      </div>
    </div>
  </xsl:template>

  <xsl:template match="header_row">
    <tr>
      <xsl:for-each select="cell">
        <th class="headerRow{key}"><xsl:value-of select="value" /></th>
      </xsl:for-each>
    </tr>
  </xsl:template>

  <xsl:template match="salesRow">
    <tr class="row{position() mod 2}">
      <xsl:for-each select="cell">
        <td class="dataRow{key}">
          <xsl:if test="key = 'Rank'">
            <xsl:choose>
              <xsl:when test="value &lt; ../cell[2]/value">
                <xsl:attribute name="class">dataRowRankUp</xsl:attribute>
              </xsl:when>
              <xsl:when test="../cell[2]/value = 'NA'">
                <xsl:attribute name="class">dataRowRankUp</xsl:attribute>
              </xsl:when>
              <xsl:when test="value &gt; ../cell[2]/value">
                <xsl:attribute name="class">dataRowRankDown</xsl:attribute>
              </xsl:when>
              <xsl:otherwise>
                <xsl:attribute name="class">dataRowRankSame</xsl:attribute>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:if>
          <xsl:choose>
            <xsl:when test="key = 'Title'">
              <a href="?c={$chartAction}&amp;period={$period}&amp;label_id={$labelId}&amp;{$chartType}={encoded_value}"><xsl:value-of select="value" /></a>
            </xsl:when>
            <xsl:when test="key = 'Service' or key = 'Format'">
              <a href="?c={$chartAction}&amp;period={$period}&amp;label_id={$labelId}&amp;{$chartType}={value}"><xsl:value-of select="value" /></a>
            </xsl:when>
            <xsl:otherwise>
              <xsl:if test="key = 'Revenue'">$</xsl:if>
              <xsl:value-of select="value" />
            </xsl:otherwise>
          </xsl:choose>
        </td>
      </xsl:for-each>
    </tr>
  </xsl:template>

  <xsl:template name="statusRow">
    <tr class="row{position()  mod 2}">
      <td><xsl:value-of select="cell[1]/value" /></td>
      <xsl:if test="cell[1]/value != 'eMusic'">
        <xsl:for-each select="cell">
          <xsl:if test="value = 0"><td>&#160;</td></xsl:if>
          <xsl:if test="value = 1"><td class="statusMonth">&#160;</td></xsl:if>
        </xsl:for-each>
      </xsl:if>
      <xsl:if test="cell[1]/value = 'eMusic'">
        <xsl:if test="cell[2]/value = 0"><td colspan="3">&#160;</td></xsl:if>
        <xsl:if test="cell[2]/value = 1"><td colspan="3" class="statusQuarter">&#160;</td></xsl:if>
      </xsl:if>
    </tr>
  </xsl:template>

</xsl:stylesheet>

