<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--                                                                  -->
<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="" encoding="utf-8" />

    <xsl:include href="/app/tools/rps/templates/global.xsl" />

    <xsl:variable name="chartPosition" />
    <xsl:variable name="chartTitle" />
    <xsl:variable name="chartAction" />
    <xsl:variable name="countryCount" select="count(Root/Report/Countries/Country)" />
    <xsl:variable name="labelCount" select="count(Root/Report/Labels/Label)" />

    <xsl:template name="pickLayout">
        <xsl:if test="$tab = 'sales' and $accessDenied != 1 and normalize-space(Report)">
            <xsl:call-template name="subSubNav" />
        </xsl:if>
        <xsl:call-template name="raptorPeriodNav" />
        <xsl:call-template name="reportsLayout" />
    </xsl:template>

    <xsl:template name="reportsLayout">
        <section class="Analytics-wrapper">
            <xsl:choose>
                <xsl:when test="$view = 'sf' and /Root/Totals/Units != '0'">
                    <xsl:call-template name="byLayout" />
                </xsl:when>
                <xsl:otherwise>
                    <xsl:choose>
                        <xsl:when test="$view = 'ls' or $view = 'gs'">
                            <xsl:call-template name="byLayout" />
                            <xsl:call-template name="topLayout" />
                        </xsl:when>
                        <xsl:when test="$view = 'fs' or $view = 'ss'">
                            <xsl:call-template name="byLayout" />
                        </xsl:when>
                        <xsl:when test="$view = 'f'">
                            <xsl:call-template name="byLayout">
                                <xsl:with-param name="chartTitle">By Service</xsl:with-param>
                                <xsl:with-param name="chartAction">ss</xsl:with-param>
                            </xsl:call-template>
                        </xsl:when>
                        <xsl:when test="$view = 's'">
                            <xsl:call-template name="byLayout">
                                <xsl:with-param name="chartTitle">By Format</xsl:with-param>
                                <xsl:with-param name="chartAction">fs</xsl:with-param>
                            </xsl:call-template>
                        </xsl:when>
                        <xsl:when test="$view = 'as' or $view = 'ks' or $view = 'rs'">
                            <xsl:call-template name="topLayout" />
                        </xsl:when>
                        <xsl:when test="$view = 'a' or $view = 'k' or $view = 'r'">
                            <xsl:call-template name="productDetailLayout" />
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:call-template name="mainLayout" />
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:if test="not(Report/Pies/Pie) and not(Report/Tables/Table) and $view != 'm' and $view != ''">
                <xsl:call-template name="noData" />
            </xsl:if>
        </section>
    </xsl:template>

    <xsl:template name="noData">
        <p>No data meets this criteria.</p>
    </xsl:template>

    <xsl:template name="greeting">
        <div class="Analytics-section Analytics-greeting">
            <div class="Analytics-greeting-inner"><xsl:call-template name="uiClientLogo" /></div>
            <div class="Analytics-greeting-inner"><xsl:call-template name="clientTotals" /></div>
            <div class="Analytics-greeting-inner"><xsl:call-template name="clientLinks" /></div>
        </div>
    </xsl:template>

    <xsl:template name="clientLinks">
        <xsl:call-template name="messages" />
    </xsl:template>

    <xsl:template name="clientTotals">
        <xsl:choose>
            <xsl:when test="Report/Totals and ((translate(Report/Totals/Revenue, translate(Report/Totals/Revenue,'0123456789', ''), '') != 0) or (translate(Report/Totals/Units, translate(Report/Totals/Units,'0123456789', ''), '') != 0))">
                <xsl:call-template name="pageTotals" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="noData" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template name="mainLayout">
        <xsl:if test="$view = 'm'">
            <xsl:call-template name="greeting" />
        </xsl:if>
        <xsl:if test="Report/Pies/Pie">
            <div class="Analytics-dualsection">
                <xsl:for-each select="Report/Pies/Pie[PieName = 'top_formats']">
                    <xsl:call-template name="pieChart">
                        <xsl:with-param name="chartTitle">Top Formats</xsl:with-param>
                        <xsl:with-param name="chartPosition">right</xsl:with-param>
                        <xsl:with-param name="chartAction">fs</xsl:with-param>
                    </xsl:call-template>
                </xsl:for-each>
                <xsl:for-each select="Report/Pies/Pie[PieName = 'top_services']">
                    <xsl:call-template name="pieChart">
                        <xsl:with-param name="chartTitle">Top Services</xsl:with-param>
                        <xsl:with-param name="chartPosition">left</xsl:with-param>
                        <xsl:with-param name="chartAction">ss</xsl:with-param>
                    </xsl:call-template>
                </xsl:for-each>
            </div>
        </xsl:if>
        <xsl:if test="Report/Tables/Table">
            <xsl:for-each select="Report/Tables/Table[TableName = 'top_albums']">
                <xsl:call-template name="salesChart">
                    <xsl:with-param name="chartTitle">Top Albums</xsl:with-param>
                    <xsl:with-param name="chartAction">as</xsl:with-param>
                </xsl:call-template>
            </xsl:for-each>
            <xsl:for-each select="Report/Tables/Table[TableName = 'top_tracks']">
                <xsl:call-template name="salesChart">
                    <xsl:with-param name="chartTitle">Top Tracks</xsl:with-param>
                    <xsl:with-param name="chartAction">ks</xsl:with-param>
                </xsl:call-template>
            </xsl:for-each>
            <xsl:for-each select="Report/Tables/Table[TableName = 'top_artists']">
                <xsl:call-template name="salesChart">
                    <xsl:with-param name="chartTitle">Top Artists</xsl:with-param>
                    <xsl:with-param name="chartAction">rs</xsl:with-param>
                </xsl:call-template>
            </xsl:for-each>
        </xsl:if>
    </xsl:template>

    <xsl:template name="byLayout">
        <xsl:param name="chartTitle" />
        <xsl:param name="chartAction" />
        <xsl:if test="Report/Pies/Pie or (Report/Totals and (translate(Report/Totals/Revenue, translate(Report/Totals/Revenue,'0123456789', ''), '') != 0) and (translate(Report/Totals/Units, translate(Report/Totals/Units,'0123456789', ''), '') != 0))">
            <div class="Analytics-section Analytics-greeting">
                <div class="Analytics-greeting-inner">
                    <xsl:choose>
                        <xsl:when test="$view = 'gs'">
                            <h2>Summary for
                                <xsl:choose>
                                    <xsl:when test="$country != ''">
                                        <xsl:value-of select="$country" />
                                    </xsl:when>
                                    <xsl:otherwise>All Countries</xsl:otherwise>
                                </xsl:choose>
                            </h2>
                        </xsl:when>
                        <xsl:when test="$view = 'ls'">
                            <h2>Summary for
                                <xsl:choose>
                                    <xsl:when test="$labelID != ''">
                                        <xsl:value-of select="$labelName" />
                                    </xsl:when>
                                    <xsl:otherwise>All Labels</xsl:otherwise>
                                </xsl:choose>
                            </h2>
                        </xsl:when>
                    </xsl:choose>
                    <xsl:call-template name="pageTotals" />
                </div>
            </div>
        </xsl:if>
        <div class="Analytics-section">
            <xsl:if test="$view != 'sf' and Report/Pies/Pie">
                <xsl:attribute name="class">Analytics-dualsection</xsl:attribute>
            </xsl:if>
            <xsl:for-each select="Report/Pies/Pie">
                <xsl:call-template name="pieChart">
                    <xsl:with-param name="chartPosition">Left</xsl:with-param>
                    <xsl:with-param name="chartTitle" select="$chartTitle" />
                    <xsl:with-param name="chartAction" select="$chartAction" />
                </xsl:call-template>
            </xsl:for-each>
        </div>
        <xsl:for-each select="Report/Tables/Table[TableName = 'top_albums']">
            <xsl:call-template name="salesChart">
                <xsl:with-param name="chartTitle">Top Albums</xsl:with-param>
                <xsl:with-param name="chartAction">as</xsl:with-param>
            </xsl:call-template>
        </xsl:for-each>
        <xsl:for-each select="Report/Tables/Table[TableName = 'top_tracks']">
            <xsl:call-template name="salesChart">
                <xsl:with-param name="chartTitle">Top Tracks</xsl:with-param>
                <xsl:with-param name="chartAction">ks</xsl:with-param>
            </xsl:call-template>
        </xsl:for-each>
        <xsl:for-each select="Report/Tables/Table[TableName = 'top_artists']">
            <xsl:call-template name="salesChart">
                <xsl:with-param name="chartTitle">Top Artists</xsl:with-param>
                <xsl:with-param name="chartAction">rs</xsl:with-param>
            </xsl:call-template>
        </xsl:for-each>
    </xsl:template>

    <xsl:template name="pageTotals">
        <p class="Analytics-totals">Total Revenue:
            <strong>
                <xsl:call-template name="formatDollars">
                    <xsl:with-param name="dollarAmount" select="Report/Totals/Revenue" />
                </xsl:call-template>
            </strong>
        </p>
        <p class="Analytics-totals">Total Units:
            <strong>
                <xsl:value-of select="Report/Totals/Units" />
            </strong>
        </p>
        <xsl:if test="Report/Totals/Rank >= 0 or Report/Totals/PrevRank >= 0">
            <p class="Analytics-totals">Rank:
                <strong>
                    <xsl:choose>
                        <xsl:when test="Report/Totals/Rank = 0">-</xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="Report/Totals/Rank" />
                        </xsl:otherwise>
                    </xsl:choose>
                </strong>
            </p>
            <p class="Analytics-totals">Last Rank:
                <strong>
                    <xsl:choose>
                        <xsl:when test="Report/Totals/PrevRank = 0">-</xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="Report/Totals/PrevRank" />
                        </xsl:otherwise>
                    </xsl:choose>
                </strong>
            </p>
        </xsl:if>
    </xsl:template>

    <xsl:template name="topLayout">
        <xsl:for-each select="Report/Tables/Table[TableName = 'top_albums']">
            <xsl:call-template name="salesChart">
                <xsl:with-param name="chartAction">as</xsl:with-param>
            </xsl:call-template>
        </xsl:for-each>
        <xsl:for-each select="Report/Tables/Table[TableName = 'top_tracks']">
            <xsl:call-template name="salesChart">
                <xsl:with-param name="chartAction">ks</xsl:with-param>
            </xsl:call-template>
        </xsl:for-each>
        <xsl:for-each select="Report/Tables/Table[TableName = 'top_artists']">
            <xsl:call-template name="salesChart">
                <xsl:with-param name="chartAction">rs</xsl:with-param>
            </xsl:call-template>
        </xsl:for-each>
        <xsl:for-each select="Report/Tables/Table[TableName = 'top_labels']">
            <xsl:call-template name="salesChart">
                <xsl:with-param name="chartAction">ms</xsl:with-param>
            </xsl:call-template>
        </xsl:for-each>
        <xsl:for-each select="Report/Tables/Table[TableName = 'top_countries']">
            <xsl:call-template name="salesChart">
                <xsl:with-param name="chartAction">ms</xsl:with-param>
            </xsl:call-template>
        </xsl:for-each>
        <xsl:if test="Report/Pies/Pie">
            <xsl:variable name="pieChartTitle">
                <xsl:if test="$view = 'ks'">Track Revenue </xsl:if>
                <xsl:if test="$view = 'as'">Album Revenue </xsl:if>
            </xsl:variable>
            <div class="Analytics-dualsection">
                <xsl:for-each select="Report/Pies/Pie[PieName = 'top_formats']">
                    <xsl:call-template name="pieChart">
                        <xsl:with-param name="chartTitle"><xsl:value-of select="$pieChartTitle" />By Format</xsl:with-param>
                        <xsl:with-param name="chartPosition">right</xsl:with-param>
                        <xsl:with-param name="chartAction">fs</xsl:with-param>
                    </xsl:call-template>
                </xsl:for-each>
                <xsl:for-each select="Report/Pies/Pie[PieName = 'top_services']">
                    <xsl:call-template name="pieChart">
                        <xsl:with-param name="chartTitle"><xsl:value-of select="$pieChartTitle" />By Service</xsl:with-param>
                        <xsl:with-param name="chartPosition">left</xsl:with-param>
                        <xsl:with-param name="chartAction">ss</xsl:with-param>
                    </xsl:call-template>
                </xsl:for-each>
            </div>
        </xsl:if>
    </xsl:template>

    <xsl:template name="rankNav">
        <xsl:param name="pageNum" />
        <xsl:if test="/Root/Report/Records/MaxPageNum &gt; 1">
            <div class="Pagination-previous-next">
                <div class="Pagination-item">
                    <xsl:if test="$pageNum != '' and $pageNum != 1">
                        <xsl:call-template name="uiButton">
                            <xsl:with-param name="url">
                                <xsl:if test="$pageNum != '' and $pageNum != 1">
                                    <xsl:call-template name="argsHref">
                                        <xsl:with-param name="baseURL">/app/reports?p=1</xsl:with-param>
                                    </xsl:call-template>
                                </xsl:if>
                            </xsl:with-param>
                            <xsl:with-param name="content" select="'First'"/>
                            <xsl:with-param name="type" select="'default'"/>
                            <xsl:with-param name="iconLeftType" select="'arrow-left'"/>
                            <xsl:with-param name="disabled">
                                <xsl:if test="not($pageNum != '' and $pageNum != 1)">
                                    <xsl:text>true</xsl:text>
                                </xsl:if>
                            </xsl:with-param>
                        </xsl:call-template>
                        <xsl:call-template name="uiButton">
                            <xsl:with-param name="url">
                                <xsl:if test="$pageNum != '' and $pageNum != 1">
                                    <xsl:call-template name="argsHref">
                                        <xsl:with-param name="baseURL">/app/reports?p=<xsl:value-of select="$pageNum - 1" /></xsl:with-param>
                                    </xsl:call-template>
                                </xsl:if>
                            </xsl:with-param>
                            <xsl:with-param name="content" select="'Previous'"/>
                            <xsl:with-param name="type" select="'default'"/>
                            <xsl:with-param name="iconLeftType" select="'arrow-left'"/>
                            <xsl:with-param name="disabled">
                                <xsl:if test="not($pageNum != '' and $pageNum != 1)">
                                    <xsl:text>true</xsl:text>
                                </xsl:if>
                            </xsl:with-param>
                        </xsl:call-template>
                    </xsl:if>
                </div>
                <div class="Pagination-item">
                    <xsl:if test="not($pageNum) or $pageNum &lt; /Root/Report/Records/MaxPageNum">
                        <xsl:call-template name="uiButton">
                            <xsl:with-param name="url">
                                <xsl:choose>
                                    <xsl:when test="$pageNum &lt; /Root/Report/Records/MaxPageNum">
                                        <xsl:call-template name="argsHref">
                                            <xsl:with-param name="baseURL">/app/reports?p=<xsl:value-of select="$pageNum + 1" /></xsl:with-param>
                                        </xsl:call-template>
                                    </xsl:when>
                                    <xsl:when test="not($pageNum)">
                                        <xsl:call-template name="argsHref">
                                            <xsl:with-param name="baseURL">/app/reports?p=<xsl:value-of select="2" /></xsl:with-param>
                                        </xsl:call-template>
                                    </xsl:when>
                                </xsl:choose>
                            </xsl:with-param>
                            <xsl:with-param name="content" select="'Next'" />
                            <xsl:with-param name="type" select="'default'"/>
                            <xsl:with-param name="iconRightType" select="'arrow-right'"/>
                            <xsl:with-param name="disabled">
                                <xsl:if test="not(not($pageNum) or $pageNum &lt; /Root/Report/Records/MaxPageNum)">
                                    <xsl:text>true</xsl:text>
                                </xsl:if>
                            </xsl:with-param>
                        </xsl:call-template>
                        <xsl:call-template name="uiButton">
                            <xsl:with-param name="url">
                                <xsl:if test="not($pageNum) or $pageNum &lt; /Root/Report/Records/MaxPageNum">
                                    <xsl:call-template name="argsHref">
                                        <xsl:with-param name="baseURL">/app/reports?p=<xsl:value-of select="/Root/Report/Records/MaxPageNum" /></xsl:with-param>
                                    </xsl:call-template>
                                </xsl:if>
                            </xsl:with-param>
                            <xsl:with-param name="content" select="'Last'"/>
                            <xsl:with-param name="type" select="'default'"/>
                            <xsl:with-param name="iconRightType" select="'arrow-right'"/>
                            <xsl:with-param name="disabled">
                                <xsl:if test="not(not($pageNum) or $pageNum &lt; /Root/Report/Records/MaxPageNum)">
                                    <xsl:text>true</xsl:text>
                                </xsl:if>
                            </xsl:with-param>
                        </xsl:call-template>
                    </xsl:if>
                </div>
            </div>
        </xsl:if>
    </xsl:template>

    <xsl:template name="productDetailLayout">
        <xsl:if test="$view != 'r' and normalize-space(Report)">
            <div class="Analytics-dualsection Analytics-dualsection-data">
                <div class="Analytics-dualsection-left Analytics-dualsection-inner">
                    <xsl:choose>
                        <xsl:when test="$view = 'a'">
                                <p>Album: <strong><xsl:value-of select="Report/ProductInfo/AlbumName" /></strong></p>
                            <xsl:if test="Report/ProductInfo/ArtistName != ''">
                                <p>Artist: <strong><xsl:value-of select="Report/ProductInfo/ArtistName" /></strong></p>
                            </xsl:if>
                            <xsl:if test="Report/ProductInfo/UPC != ''">
                                <p>UPC: <strong><xsl:value-of select="Report/ProductInfo/UPC" /></strong></p>
                            </xsl:if>
                            <xsl:if test="Report/ProductInfo/CatalogID != ''">
                                <p>Catalog ID: <strong><xsl:value-of select="Report/ProductInfo/CatalogID" /></strong></p>
                            </xsl:if>
                        </xsl:when>
                        <xsl:when test="$view = 'k'">
                            <p>Track: <strong><xsl:value-of select="Report/ProductInfo/TrackName" /></strong></p>
                            <xsl:if test="Report/ProductInfo/ArtistName != ''">
                                <p>Artist: <strong><xsl:value-of select="Report/ProductInfo/ArtistName" /></strong></p>
                            </xsl:if>
                            <xsl:if test="Report/ProductInfo/AlbumName != ''">
                                <p>Album: <strong><xsl:value-of select="Report/ProductInfo/AlbumName" /></strong></p>
                            </xsl:if>
                            <xsl:if test="Report/ProductInfo/ISRC != ''">
                                <p>ISRC: <strong><xsl:value-of select="Report/ProductInfo/ISRC" /></strong></p>
                            </xsl:if>
                            <xsl:if test="Report/ProductInfo/UPC != ''">
                                <p>UPC: <strong><xsl:value-of select="Report/ProductInfo/UPC" /></strong></p>
                            </xsl:if>
                            <xsl:if test="Report/ProductInfo/CatalogID != ''">
                                <p>Catalog ID: <strong><xsl:value-of select="Report/ProductInfo/CatalogID" /></strong></p>
                            </xsl:if>
                        </xsl:when>
                    </xsl:choose>
                </div>
                <div class="Analytics-dualsection-right Analytics-dualsection-inner">
                    <xsl:call-template name="pageTotals" />
                </div>
            </div>
        </xsl:if>
        <xsl:if test="$view = 'r' and normalize-space(Report)">
            <div class="Analytics-section" id="totals">
                <xsl:call-template name="pageTotals" />
            </div>
        </xsl:if>
        <xsl:if test="Report/Pies/Pie">
            <div class="Analytics-dualsection">
                <xsl:for-each select="Report/Pies/Pie[PieName = 'top_services']">
                    <xsl:call-template name="pieChart">
                        <xsl:with-param name="chartTitle">By Service</xsl:with-param>
                        <xsl:with-param name="chartPosition">left</xsl:with-param>
                        <xsl:with-param name="chartAction">ss</xsl:with-param>
                    </xsl:call-template>
                </xsl:for-each>
                <xsl:for-each select="Report/Pies/Pie[PieName = 'top_formats']">
                    <xsl:call-template name="pieChart">
                        <xsl:with-param name="chartTitle">By Format</xsl:with-param>
                        <xsl:with-param name="chartPosition">right</xsl:with-param>
                        <xsl:with-param name="chartAction">fs</xsl:with-param>
                    </xsl:call-template>
                </xsl:for-each>
            </div>
        </xsl:if>
        <xsl:if test="Report/Tables/Table">
            <div class="Analytics-dualsection">
                <xsl:for-each select="Report/Tables/Table[TableName = 'track_revenue_by_service' or TableName = 'album_revenue_by_service' or TableName = 'artist_revenue_by_service']">
                    <xsl:call-template name="salesChart">
                        <xsl:with-param name="chartPosition">left</xsl:with-param>
                        <xsl:with-param name="chartAction">s</xsl:with-param>
                    </xsl:call-template>
                </xsl:for-each>
                <xsl:for-each select="Report/Tables/Table[TableName = 'track_revenue_by_format' or TableName = 'album_revenue_by_format' or TableName = 'artist_revenue_by_format']">
                    <xsl:call-template name="salesChart">
                        <xsl:with-param name="chartPosition">right</xsl:with-param>
                        <xsl:with-param name="chartAction">f</xsl:with-param>
                    </xsl:call-template>
                </xsl:for-each>
            </div>
        </xsl:if>
    </xsl:template>

    <xsl:template name="chartTitle">
        <xsl:param name="chartTitle" />
        <xsl:param name="chartAction" />
        <xsl:if test="normalize-space($chartTitle)">
            <h3>
                <a>
                    <xsl:call-template name="argsLink">
                        <xsl:with-param name="skip">c</xsl:with-param>
                        <xsl:with-param name="skip2">format</xsl:with-param>
                        <xsl:with-param name="baseURL">/app/reports?c=<xsl:value-of select="$chartAction" /></xsl:with-param>
                    </xsl:call-template>
                    <xsl:value-of select="$chartTitle" />
                </a>
            </h3>
        </xsl:if>
    </xsl:template>

    <xsl:template name="pieChart">
        <xsl:param name="chartPosition" />
        <xsl:param name="chartTitle" />
        <xsl:param name="chartAction" />

        <div class="Analytics-dualsection-inner Analytics-dualsection-{$chartPosition}">
            <xsl:call-template name="chartTitle">
                <xsl:with-param name="chartTitle" select="$chartTitle" />
                <xsl:with-param name="chartAction" select="$chartAction" />
            </xsl:call-template>
            <div class="PieChart">
                <xsl:attribute name="data-items">
                    [
                        <xsl:for-each select="Legend/Item">

                            <xsl:variable name="pieSectionTip">
                                <xsl:call-template name="pieSectionTip">
                                    <xsl:with-param name="value" select="Value" />
                                </xsl:call-template>
                            </xsl:variable>

                            {
                                "value": "<xsl:value-of select="Value" />",
                                "label": "<xsl:value-of select="Label" />",
                                "link": "<xsl:value-of select="Link" />",
                                "color": "<xsl:value-of select="Color" />",
                                "sectionTip": "<xsl:value-of select="$pieSectionTip" />"
                            }
                            <xsl:if test="position() != last()">,</xsl:if>
                        </xsl:for-each>
                    ]
                </xsl:attribute>
            </div>
            <div class="Analytics-pielegend">
                <xsl:for-each select="Legend/Item">
                    <p class="Analytics-pielegend-item">

                        <xsl:variable name="pieSectionTip">
                            <xsl:call-template name="pieSectionTip">
                                <xsl:with-param name="value" select="Value" />
                            </xsl:call-template>
                        </xsl:variable>
                        <xsl:if test="Color !='#0'">
                            <i class="Analytics-legendcolor" style="background-color: {Color}"/>
                        </xsl:if>
                        <xsl:value-of select="Percent" />&#160;&#x2014;&#160;
                        <a class="js-tooltip" title="{$pieSectionTip}">
                            <xsl:if test="Link != 'NONE'">
                                <xsl:attribute name="href">
                                    <xsl:value-of select="Link" />
                                </xsl:attribute>
                            </xsl:if>
                            <xsl:value-of select="Label" />
                        </a>
                    </p>
                </xsl:for-each>
                <xsl:if test="Legend/ExtraItem">
                    <div class="Analytics-pielegend">
                        <xsl:for-each select="Legend/ExtraItem">
                            <p class="Analytics-pielegend-item">
                                <a href="{Link}" class="js-tooltip" title="{Label}">
                                    <xsl:value-of select="Label" />
                                </a>
                            </p>
                        </xsl:for-each>
                    </div>
                </xsl:if>
            </div>
        </div>
    </xsl:template>

    <xsl:template name="salesChart">
        <xsl:param name="chartPosition" />
        <xsl:param name="chartTitle" />
        <xsl:param name="chartAction" />

        <xsl:call-template name="chartTitle">
            <xsl:with-param name="chartTitle" select="$chartTitle" />
            <xsl:with-param name="chartAction" select="$chartAction" />
        </xsl:call-template>

        <div class="Analytics-section">
            <xsl:if test="$chartPosition">
                <xsl:attribute name="class">Analytics-dualsection-inner Analytics-dualsection-<xsl:value-of select="$chartPosition"/></xsl:attribute>
            </xsl:if>
            <xsl:call-template name="rankNav">
                <xsl:with-param name="pageNum" select="/Root/Params/p" />
            </xsl:call-template>

            <table class="Table Table-with-highlight">
                <thead>
                    <xsl:call-template name="headerRow" />
                </thead>
                <tbody>
                    <xsl:for-each select="DataRow">
                        <xsl:call-template name="dataRow">
                            <xsl:with-param name="chartAction">
                                <xsl:value-of select="substring($chartAction,1,1)"/>
                            </xsl:with-param>
                        </xsl:call-template>
                    </xsl:for-each>
                </tbody>
            </table>
            <xsl:call-template name="rankNav">
                <xsl:with-param name="pageNum" select="/Root/Params/p" />
            </xsl:call-template>
        </div>
    </xsl:template>

    <xsl:template name="headerRow">
        <tr class="Table-row Table-row-header">
            <xsl:for-each select="HeaderRow/Cell">
                <th>
                    <xsl:attribute name="class">
                        <xsl:text>Table-col </xsl:text>
                        <xsl:choose>
                            <xsl:when test="Value = 'ProductInfo' or Value = 'ArtistInfo'">Analytics-coltitle Analytics-colSticky</xsl:when>
                            <xsl:when test="Value = 'PrevRank' or Value = 'Rank'">Analytics-colRank Analytics-colSticky</xsl:when>
                        </xsl:choose>
                        <xsl:if test="Value = 'Units' or Value = 'Revenue' or Key = 'Data'">Analytics-colnumbers Table-col-amount</xsl:if>
                    </xsl:attribute>
                    <xsl:choose>
                        <xsl:when test="Value = 'ProductInfo'">
                            <xsl:choose>
                                <xsl:when test="../../TableName = 'track_revenue_by_service' or ../../TableName = 'album_revenue_by_service' or ../../TableName = 'artist_revenue_by_service'">Service</xsl:when>
                                <xsl:when test="../../TableName = 'track_revenue_by_format' or ../../TableName = 'album_revenue_by_format' or ../../TableName = 'artist_revenue_by_format'">Format</xsl:when>
                                <xsl:when test="../../TableName = 'top_labels'">Label Name</xsl:when>
                                <xsl:when test="../../TableName = 'top_countries'">Country</xsl:when>
                                <xsl:otherwise>Title</xsl:otherwise>
                            </xsl:choose>
                        </xsl:when>
                        <xsl:when test="Value = 'ArtistInfo'">Artist</xsl:when>
                        <xsl:when test="Value = 'PrevRank'">Last&#160;Rank</xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="Value" />
                        </xsl:otherwise>
                    </xsl:choose>
                </th>
            </xsl:for-each>
        </tr>
    </xsl:template>

    <xsl:template name="dataRow">
        <xsl:param name="chartAction" />
        <tr class="Table-row Table-row-data">
            <xsl:for-each select="Cell">
                <td>
                    <xsl:attribute name="class">Table-col Analytics-col<xsl:value-of select="Key" />
                        <xsl:if test="Key = 'Rank'">
                            <xsl:choose>
                                <xsl:when test="Value = '' and ../Cell[Key = 'PrevRank']/Value = ''"> Analytics-rank-same Analytics-colSticky</xsl:when>
                                <xsl:when test="Value &lt; ../Cell[Key = 'PrevRank']/Value or ../Cell[Key = 'PrevRank']/Value = 'NA' or ../Cell[Key = 'PrevRank']/Value = ''"> Analytics-rank-up Analytics-colSticky</xsl:when>
                                <xsl:when test="Value &gt; ../Cell[Key = 'PrevRank']/Value"> Analytics-rank-down Analytics-colSticky</xsl:when>
                                <xsl:otherwise> Analytics-rank-same Analytics-colSticky</xsl:otherwise>
                            </xsl:choose>
                        </xsl:if>
                        <xsl:if test="Key = 'PrevRank'">
                            <xsl:value-of select="' Analytics-colSticky'" />
                        </xsl:if>
                        <xsl:if test="Key = 'ProductInfo'">
                            <xsl:value-of select="' Analytics-colSticky'" />
                        </xsl:if>
                        <xsl:if test="Key = 'ArtistInfo'">
                            <xsl:value-of select="' Analytics-colSticky'" />
                        </xsl:if>
                        <xsl:if test="Key = 'Service'">
                            <xsl:value-of select="' Analytics-colSticky'" />
                        </xsl:if>
                        <xsl:if test="Key = 'Format'">
                            <xsl:value-of select="' Analytics-colSticky'" />
                        </xsl:if>
                    </xsl:attribute>
                    <xsl:choose>
                        <xsl:when test="Key = 'ProductInfo' or Key = 'ArtistInfo' or Key = 'Service' or Key = 'Format'">
                            <a class="Analytics-reportmainlink">
                                <xsl:variable name="baseURL">/app/reports?c=<xsl:value-of select="$chartAction" /></xsl:variable>
                                <xsl:choose>
                                    <xsl:when test="ProductInfo/TrackName or ProductInfo/AlbumName">
                                        <xsl:call-template name="argsLink">
                                            <xsl:with-param name="skip">c</xsl:with-param>
                                            <xsl:with-param name="baseURL">
                                                <xsl:value-of select="$baseURL" />&amp;product=<xsl:value-of select="ProductInfo/ProductID" />
                                            </xsl:with-param>
                                            <xsl:with-param name="skip2">product</xsl:with-param>
                                            <xsl:with-param name="skip3">format</xsl:with-param>
                                            <xsl:with-param name="skip4">service</xsl:with-param>
                                        </xsl:call-template>
                                    </xsl:when>
                                    <xsl:when test="ArtistInfo/ArtistName">
                                        <xsl:call-template name="argsLink">
                                            <xsl:with-param name="skip">c</xsl:with-param>
                                            <xsl:with-param name="baseURL">
                                                <xsl:value-of select="$baseURL" />&amp;artist=<xsl:value-of select="ArtistInfo/ArtistID" />
                                            </xsl:with-param>
                                            <xsl:with-param name="skip2">artist</xsl:with-param>
                                            <xsl:with-param name="skip3">format</xsl:with-param>
                                            <xsl:with-param name="skip4">service</xsl:with-param>
                                        </xsl:call-template>
                                    </xsl:when>
                                    <xsl:when test="ProductInfo/ServiceName">
                                        <xsl:call-template name="argsLink">
                                            <xsl:with-param name="skip">c</xsl:with-param>
                                            <xsl:with-param name="baseURL">
                                                <xsl:value-of select="$baseURL" />&amp;service=<xsl:value-of select="ProductInfo/ServiceID" />
                                            </xsl:with-param>
                                            <xsl:with-param name="skip2">service</xsl:with-param>
                                            <xsl:with-param name="skip3">format</xsl:with-param>
                                        </xsl:call-template>
                                    </xsl:when>
                                    <xsl:when test="ProductInfo/LabelID">
                                        <xsl:call-template name="argsLink">
                                            <xsl:with-param name="skip">c</xsl:with-param>
                                            <xsl:with-param name="baseURL">
                                                <xsl:value-of select="$baseURL" />&amp;label=<xsl:value-of select="ProductInfo/LabelID" />
                                            </xsl:with-param>
                                            <xsl:with-param name="skip2">label</xsl:with-param>
                                            <xsl:with-param name="skip3">format</xsl:with-param>
                                            <xsl:with-param name="skip4">service</xsl:with-param>
                                        </xsl:call-template>
                                    </xsl:when>
                                    <xsl:when test="ProductInfo/CountryID">
                                        <xsl:call-template name="argsLink">
                                            <xsl:with-param name="skip">c</xsl:with-param>
                                            <xsl:with-param name="baseURL">
                                                <xsl:value-of select="$baseURL" />&amp;country=<xsl:value-of select="ProductInfo/CountryID" />
                                            </xsl:with-param>
                                            <xsl:with-param name="skip2">country</xsl:with-param>
                                            <xsl:with-param name="skip3">format</xsl:with-param>
                                            <xsl:with-param name="skip4">service</xsl:with-param>
                                        </xsl:call-template>
                                    </xsl:when>
                                    <xsl:when test="ProductInfo/FormatType">
                                        <xsl:call-template name="argsLink">
                                            <xsl:with-param name="skip">c</xsl:with-param>
                                            <xsl:with-param name="baseURL">
                                                <xsl:value-of select="$baseURL" />&amp;format=<xsl:value-of select="ProductInfo/FormatType" />
                                            </xsl:with-param>
                                            <xsl:with-param name="skip2">format</xsl:with-param>
                                            <xsl:with-param name="skip3">service</xsl:with-param>
                                        </xsl:call-template>
                                    </xsl:when>
                                </xsl:choose>
                                <xsl:value-of select="ProductInfo/TrackName" />
                                <xsl:value-of select="ProductInfo/AlbumName" />
                                <xsl:value-of select="ArtistInfo/ArtistName" />
                                <xsl:value-of select="ProductInfo/ServiceName" />
                                <xsl:value-of select="ProductInfo/FormatName" />
                                <xsl:value-of select="ProductInfo/LabelName" />
                                <xsl:value-of select="ProductInfo/CountryName" />
                            </a>
                            <xsl:if test="ProductInfo/ArtistName">
                                <br />
                                <a href="/app/reports?c=r&amp;artist={ProductInfo/ArtistID}" class="reportSmallLink">
                                    <xsl:variable name="baseURL">/app/reports?c=r</xsl:variable>
                                    <xsl:call-template name="argsLink">
                                        <xsl:with-param name="skip">c</xsl:with-param>
                                        <xsl:with-param name="baseURL">
                                            <xsl:value-of select="$baseURL" />&amp;artist=<xsl:value-of select="ProductInfo/ArtistID" />
                                        </xsl:with-param>
                                        <xsl:with-param name="skip2">artist</xsl:with-param>
                                        <xsl:with-param name="skip3">format</xsl:with-param>
                                        <xsl:with-param name="skip4">service</xsl:with-param>
                                    </xsl:call-template>
                                    <xsl:value-of select="ProductInfo/ArtistName" />
                                </a>
                                <xsl:if test="(ProductInfo/AlbumName != '' or ProductInfo/TrackName != '') and ProductInfo/CatalogID != ''">
                                    <span class="reportCatId"> (<xsl:value-of select="ProductInfo/CatalogID"/>)</span>
                                </xsl:if>
                            </xsl:if>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:choose>
                                <xsl:when test="Value = ''">-</xsl:when>
                                <xsl:when test="Key = 'Revenue' or Key = 'Data'">
                                    <xsl:call-template name="formatDollars">
                                        <xsl:with-param name="dollarAmount" select="Value" />
                                    </xsl:call-template>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="Value" />
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:otherwise>
                    </xsl:choose>
                </td>
            </xsl:for-each>
        </tr>
    </xsl:template>

    <xsl:template name="statusChart">
        <div class="sectionHeader">
            <h1>Sales Data Status</h1>
        </div>
        <div class="sectionBody">
            <div class="Analytics-section" id="statusChart">
                <table class="Table Table-with-highlight">
                    <thead>
                        <tr class="Table-row Table-row-header">
                            <xsl:for-each select="HeaderRow/Cell">
                                <th class="Table-col">
                                    <xsl:value-of select="Value" />
                                </th>
                            </xsl:for-each>
                        </tr>
                    </thead>
                    <tbody>
                        <xsl:for-each select="DataRow">
                            <tr class="Table-row Table-row-data">
                                <td class="Table-col">
                                    <xsl:value-of select="Cell[1]/Value" />
                                </td>
                                <xsl:for-each select="Cell[position() &gt; 1]">
                                    <xsl:if test="Value = 0">
                                        <td class="Table-col">&#160;</td>
                                    </xsl:if>
                                    <xsl:if test="Value = 1">
                                        <td class="Table-col">&#160;</td>
                                    </xsl:if>
                                </xsl:for-each>
                            </tr>
                        </xsl:for-each>
                    </tbody>
                </table>
            </div>
        </div>
    </xsl:template>

</xsl:stylesheet>
