<!--                                                                  -->
<!--  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="text" indent="no" />
  
  <xsl:include href="/app/tools/common/production/templates/text_templates.xsl" />   


  <!-- US Mechanicals are always paid in US Dollars, so it's fairly safe to hard code this stuff -->

  <xsl:variable name="currencyCode" select="/Root/MechanicalRun/MechanicalStatementList/MechanicalStatement/AmountDue/@currency_code" />
  <xsl:variable name="currencySymbol" select="/Root/MechanicalRun/MechanicalStatementList/MechanicalStatement/AmountDue/@currency_symbol" />
  <xsl:variable name="thousands" select="/Root/Client/Locale/NumericFormat/Thousands" />

	<xsl:template match="Root">
		<xsl:call-template name="showHeader" />
		<xsl:for-each select="MechanicalRun/MechanicalStatementList/MechanicalStatement"><xsl:call-template name="showLine" /></xsl:for-each>
	</xsl:template>

	<xsl:template name="showHeader">
  	<xsl:text>Publisher</xsl:text>
  	<xsl:value-of select="$tab" />
  	<xsl:text>Client #</xsl:text>
  	<xsl:value-of select="$tab" />
  	<xsl:text>Previous Balance (</xsl:text><xsl:value-of select="$currencyCode" /><xsl:text>)</xsl:text>
  	<xsl:value-of select="$tab" />
  	<xsl:text>Transaction Total (</xsl:text><xsl:value-of select="$currencyCode" /><xsl:text>)</xsl:text>
  	<xsl:value-of select="$tab" />
  	<xsl:text>Period Royalties (</xsl:text><xsl:value-of select="$currencyCode" /><xsl:text>)</xsl:text>
  	<xsl:value-of select="$tab" />
    <xsl:text>Ending Balance (</xsl:text><xsl:value-of select="$currencyCode" /><xsl:text>)</xsl:text>
  	<xsl:value-of select="$tab" />
    <xsl:text>Minimum Payment (</xsl:text><xsl:value-of select="$currencyCode" /><xsl:text>)</xsl:text>
  	<xsl:value-of select="$tab" />
    <xsl:text>Amount Payable (</xsl:text><xsl:value-of select="$currencyCode" /><xsl:text>)</xsl:text>
    <xsl:value-of select="$newLine" />
	</xsl:template>    
    
	<xsl:template name="showLine">	    
  	<xsl:value-of select="Publisher/PublisherName" />
  	<xsl:value-of select="$tab" />
  	<xsl:value-of select="Publisher/ClientAccountID" />
    <xsl:value-of select="$tab" />
    <xsl:call-template name="cleanNumber">
      <xsl:with-param name="number" select="PreviousBalance" />
    </xsl:call-template>
		<xsl:value-of select="$tab" />
    <xsl:call-template name="cleanNumber">
      <xsl:with-param name="number" select="TransactionSubtotal" />
    </xsl:call-template>		
		<xsl:value-of select="$tab" />
    <xsl:call-template name="cleanNumber">
      <xsl:with-param name="number" select="Subtotal" />
    </xsl:call-template>			
		<xsl:value-of select="$tab" />
    <xsl:call-template name="cleanNumber">
      <xsl:with-param name="number" select="StatementTotal" />
    </xsl:call-template>			
		<xsl:value-of select="$tab" />
    <xsl:call-template name="cleanNumber">
      <xsl:with-param name="number" select="MinimumPayment" />
    </xsl:call-template>		
		<xsl:value-of select="$tab" />
  	<xsl:choose>
  		<xsl:when test="OnHold = 1">ON-HOLD</xsl:when>
  		<xsl:otherwise>
        <xsl:call-template name="cleanNumber">
          <xsl:with-param name="number" select="AmountDue" />
        </xsl:call-template>		  		
    	</xsl:otherwise>
    </xsl:choose>
		<xsl:value-of select="$newLine" />
  </xsl:template>
  
  <xsl:template name="cleanNumber">
    <xsl:param name="number" />
    <xsl:value-of select="translate(translate($number,$currencySymbol,''),$thousands,'')" />
  </xsl:template>  

</xsl:stylesheet>
