<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="date">

  <xsl:variable name="action"><xsl:value-of select="/Root/App" /></xsl:variable>
  <xsl:variable name="view"><xsl:value-of select="/Root/Params/view" /></xsl:variable>
  <xsl:variable name="service"><xsl:value-of select="/Root/Params/service" /></xsl:variable>
  <xsl:variable name="format"><xsl:value-of select="/Root/Params/format" /></xsl:variable>
  <xsl:variable name="artist"><xsl:value-of select="/Root/Params/artist" /></xsl:variable>
  <xsl:variable name="country_code"><xsl:value-of select="/Root/Params/country" /></xsl:variable>
  <xsl:variable name="country"><xsl:value-of select="/Root/Country" /></xsl:variable>

  <xsl:variable name="now" select="date:date-time()"/>

  <xsl:variable name="files">
    <xsl:if test="normalize-space(/Root/Files/File/OrigFileName)">1</xsl:if>
  </xsl:variable>

  <xsl:variable name="filesClosed">
    <xsl:for-each select="/Root/Files/File">
      <xsl:if test="FileStatus = 5">1</xsl:if>
    </xsl:for-each>
  </xsl:variable>

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

  <xsl:variable name="labelID">
    <xsl:choose>
      <xsl:when test="/Root/Label/LabelID">
        <xsl:value-of select="/Root/Label/LabelID" />
      </xsl:when>
      <xsl:otherwise><xsl:value-of select="/Root/Params/label" /></xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name="labelName">
    <xsl:choose>
      <xsl:when test="$labelID != ''">
        <xsl:value-of select="/Root/Label/LabelName" />
      </xsl:when>
      <xsl:when test="/Root/Params/view != 'ls' and $labelCount &gt; 1">
        All Labels
      </xsl:when>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name="period"><xsl:value-of select="/Root/Period/PeriodID" /></xsl:variable>
  <xsl:variable name="periodType"><xsl:value-of select="translate(/Root/Period/PeriodType, 'YQM','yqm')" /></xsl:variable>

  <xsl:variable name="tab">
    <xsl:if test="$action = 'reports'">sales</xsl:if>
    <xsl:if test="$action = 'tracker' or $action = 'matcher' or $action = 'streamRevenue' or $action = 'finishImport'">royalties</xsl:if>
    <xsl:if test="$action = 'users' or $action = 'user_edit' or $action = 'profile' or $action = 'changepw' or $action = 'import_user'">users</xsl:if>
    <xsl:if test="$action = 'contact'">contact</xsl:if>
  </xsl:variable>

  <xsl:variable name="currentParamListClean">
    <xsl:for-each select="/Root/Params/*">
      <xsl:if test="name() != 'cmd' and name() != 'subcmd' and name() != 'url'">%26<xsl:value-of select="name()" />=<xsl:value-of select="current()" /></xsl:if>
    </xsl:for-each>
  </xsl:variable>

  <xsl:variable name="pageName">
    <xsl:if test="$action = 'changepw'">Change Password</xsl:if>
    <xsl:if test="$action = 'login'">Login</xsl:if>
    <xsl:if test="$action = 'tracker'">
      <xsl:choose>
        <xsl:when test="Root/Params/cmd = 'notes' and not(Root/Params/sub_cmd)">View/Edit Notes</xsl:when>
        <xsl:when test="Root/Params/cmd = 'edit_period' and not(Root/Params/sub_cmd)">Edit Period Name</xsl:when>
        <xsl:when test="Root/Params/cmd = 'revenue'">Input Revenue</xsl:when>
        <xsl:when test="Root/Params/cmd = 'currency'">Currency Conversion</xsl:when>
        <xsl:when test="Root/Params/cmd = 'finish'">Finish Import</xsl:when>
        <xsl:otherwise>Royalty Status Tracker</xsl:otherwise>
      </xsl:choose>
    </xsl:if>
    <xsl:if test="$action = 'matcher'">Manage Import</xsl:if>
    <xsl:if test="$action = 'streamRevenue'">Stream Revenue</xsl:if>
    <xsl:if test="$action = 'finishImport'">Finish Import</xsl:if>
    <xsl:if test="$action = 'users'">User Summary</xsl:if>
    <xsl:if test="$action = 'user_edit'">
      <xsl:choose>
        <xsl:when test="normalize-space(/Root/Params/user)">
          Edit User Info
        </xsl:when>
        <xsl:otherwise>
          Add New User
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
    <xsl:if test="$action = 'reports'">
      <xsl:choose>
        <xsl:when test="$view = 'sf'"><xsl:value-of select="/Root/ProductInfo/ServiceName" /> - <xsl:value-of select="/Root/ProductInfo/FormatName" /> Revenue </xsl:when>
        <xsl:when test="$view = 'fs'">Revenue By Format </xsl:when>
        <xsl:when test="$view = 'ss'">Revenue By Service </xsl:when>
        <xsl:when test="$view = 'gs'">Revenue By Country </xsl:when>
        <xsl:when test="$view = 'as'">Top Albums </xsl:when>
        <xsl:when test="$view = 'ks'">Top Tracks </xsl:when>
        <xsl:when test="$view = 'rs'">Top Artists </xsl:when>
        <xsl:when test="$view = 'ls'">Top Labels </xsl:when>
        <xsl:when test="$view = 'f'"><xsl:value-of select="/Root/ProductInfo/FormatName" /> Revenue </xsl:when>
        <xsl:when test="$view = 's'"><xsl:value-of select="/Root/ProductInfo/ServiceName" />  Revenue </xsl:when>
        <xsl:when test="$view = 'a'"><xsl:value-of select="/Root/ProductInfo/AlbumName" /><xsl:text> </xsl:text></xsl:when>
        <xsl:when test="$view = 'k'"><xsl:value-of select="/Root/ProductInfo/TrackName" /><xsl:text> </xsl:text></xsl:when>
        <xsl:when test="$view = 'r'"><xsl:value-of select="/Root/ArtistInfo/ArtistName" /><xsl:text> </xsl:text></xsl:when>
        <xsl:otherwise>Digital Sales Dashboard </xsl:otherwise>
      </xsl:choose>
      <xsl:if test="$country_code != '' and $view != 'gs'">- <xsl:value-of select="$country" />&#160;</xsl:if>
      <xsl:if test="$labelName != '' and $view != 'ls'">- <xsl:value-of select="$labelName" /></xsl:if>
    </xsl:if>
    <xsl:if test="$action = 'forgotpw' and not(/Root/Params/new)">Forgot Password</xsl:if>
    <xsl:if test="$action = 'forgotpw' and /Root/Params/new">Set Password</xsl:if>
    <xsl:if test="$action = 'contact'">Contact</xsl:if>
    <xsl:if test="$action = 'profile'">View/Edit Profile</xsl:if>
    <xsl:if test="$action = 'import_user'">Import User</xsl:if>
  </xsl:variable>

</xsl:stylesheet>

