<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ccbnxml="http://xml.corporate-ir.net" exclude-result-prefixes="xsl xmlns ccbnxml">
    <!--'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    INCLUDES
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''-->
    <!--'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    OUTPUT MEHTOD
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''-->
    <xsl:output method="html" omit-xml-declaration="yes" indent="yes" standalone="no"/>
    <!--'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    GLOBAL PARAMETERS
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''-->
    <!--'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    GLOBAL VARIABLES
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''-->
    <!--''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    MAIN TEMPLATE
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''-->
    
    <xsl:template match="/">
           <xsl:variable name="strLanguage" select="'ENC'" />
      <xsl:choose>
        <xsl:when test="$strLanguage = 'ENC'">
            <xsl:call-template name="EN"/>
        </xsl:when>  
        <xsl:otherwise>
            <xsl:call-template name="FR"/>
        </xsl:otherwise>
      </xsl:choose> 
    </xsl:template>
    
    <xsl:template name="FR">

<div id="stockQuoteZone">
    <table cellspacing="0" cellpadding="0" class="HomeStockQuote">
    <tr>
    <td colspan="3">
        <span class="Title">Stock Quotes</span>
        <span class="Date" ><xsl:call-template name="DisplayDateFR"><xsl:with-param name="strDate" select="/*/StockQuotes/Stock_Quote[@Company = 'Domtar Corporation']/Date/@Date"/></xsl:call-template></span><br />
        <span class="Date"><xsl:text>&#160;&#160;</xsl:text><xsl:call-template name="DisplayTimeFR"><xsl:with-param name="strTime" select="/*/StockQuotes/Stock_Quote[@Company = 'Domtar Corporation']/Date/@Time"/></xsl:call-template>&#160;PT</span>
    </td> 
       </tr>
    <tr class="ActiveBG">
    <td class="stockName">NYSE</td>
    <xsl:variable name="previous" select="/*/StockQuotes/Stock_Quote[@Class = 'NYSE']/PreviousClose" />
    <xsl:variable name="chg" select="/*/StockQuotes/Stock_Quote[@Class = 'NYSE']/Change" />
    <td class="stockPrice" align="right"><div style="margin-right: 22px!important;"><xsl:value-of select="/*/StockQuotes/Stock_Quote[@Class = 'NYSE']/Trade"/>$</div></td>
    <td class="stockDiff">
        <div>
            <xsl:choose>
                <xsl:when test="$chg &gt; 0">
                    <xsl:attribute name="class">stockDiffUp</xsl:attribute>
                </xsl:when>
                 <xsl:otherwise>
                      <xsl:attribute name="class">stockDiffDown</xsl:attribute>
                 </xsl:otherwise>
            </xsl:choose>
            <xsl:value-of select="$chg"/>&#160;(<xsl:value-of select="format-number($chg * 100 div $previous, '#0.0') "/>%)
        </div>
    </td>    
    </tr>
    <tr>
    <td class="stockName">TSX</td>
    <xsl:variable name="previous" select="/*/StockQuotes/Stock_Quote[@Class = 'TSX']/PreviousClose" />
    <xsl:variable name="chg" select="/*/StockQuotes/Stock_Quote[@Class = 'TSX']/Change" />
    <td class="stockPrice" align="right"><div><xsl:value-of select="/*/StockQuotes/Stock_Quote[@Class = 'TSX']/Trade"/>$<span class="stockCurrency">CAN</span></div></td>
    <td class="stockDiff">
        <div>
            <xsl:choose>
                <xsl:when test="$chg &gt; 0">
                    <xsl:attribute name="class">stockDiffUp</xsl:attribute>
                </xsl:when>
                 <xsl:otherwise>
                      <xsl:attribute name="class">stockDiffDown</xsl:attribute>
                 </xsl:otherwise>
            </xsl:choose>
            <xsl:value-of select="$chg"/>&#160;(<xsl:value-of select="format-number($chg * 100 div $previous, '#0.0') "/>%)
        </div>
    </td>        
    </tr>
    </table>
    <div class="delayed">Informations mises &#224; jours toutes les 20 minutes</div>
    <div class="refresh" onclick="document.location.reload(true);">Actualiser<br />les donn&#233;es</div>
    <div class="moreQuote"><a href="/en/investors/information/4822.asp" target="_top">Voir le cours<br />de l'action <img src="/greenArrowBG.gif" /></a></div>
</div>

<!--page-level template-->
    </xsl:template>


<xsl:template name="EN">
<div id="stockQuoteZone">
    <table cellspacing="0" cellpadding="0" class="HomeStockQuote">
    <tr>
        <td colspan="3">
            <span class="Title">Stock Quotes</span>
            <span class="Date" ><xsl:call-template name="DisplayDateEN"><xsl:with-param name="strDate" select="/*/StockQuotes/Stock_Quote[@Company = 'Domtar Corporation']/Date/@Date"/></xsl:call-template></span><br />
            <span class="Date"><xsl:text>&#160;at&#160;</xsl:text><xsl:call-template name="DisplayTimeEN"><xsl:with-param name="strTime" select="/*/StockQuotes/Stock_Quote[@Company = 'Domtar Corporation']/Date/@Time"/></xsl:call-template>&#160;ET</span>
        </td>
    </tr>
    <tr class="ActiveBG">
    <td class="stockName">NYSE</td>
    <xsl:variable name="previous" select="/*/StockQuotes/Stock_Quote[@Class = 'NYSE']/PreviousClose" />
    <xsl:variable name="chg" select="/*/StockQuotes/Stock_Quote[@Class = 'NYSE']/Change" />
    <td class="stockPrice" align="right"><div>$<xsl:value-of select="/*/StockQuotes/Stock_Quote[@Class = 'NYSE']/Trade"/></div></td>
    <td class="stockDiff">
        <div>
            <xsl:choose>
                <xsl:when test="$chg &gt; 0">
                    <xsl:attribute name="class">stockDiffUp</xsl:attribute>
                </xsl:when>
                 <xsl:otherwise>
                      <xsl:attribute name="class">stockDiffDown</xsl:attribute>
                 </xsl:otherwise>
            </xsl:choose>
            <xsl:value-of select="$chg"/>&#160;(<xsl:value-of select="format-number($chg * 100 div $previous, '#0.0') "/>%)
        </div>
    </td>    
    </tr>
    <tr>
    <td class="stockName">TSX</td>
    <xsl:variable name="previous" select="/*/StockQuotes/Stock_Quote[@Class = 'TSX']/PreviousClose" />
    <xsl:variable name="chg" select="/*/StockQuotes/Stock_Quote[@Class = 'TSX']/Change" />
    <td class="stockPrice" align="right"><div><span class="stockCurrency">CAD</span>$<xsl:value-of select="/*/StockQuotes/Stock_Quote[@Class = 'TSX']/Trade"/></div></td>
    <td class="stockDiff">
        <div>
            <xsl:choose>
                <xsl:when test="$chg &gt; 0">
                    <xsl:attribute name="class">stockDiffUp</xsl:attribute>
                </xsl:when>
                 <xsl:otherwise>
                      <xsl:attribute name="class">stockDiffDown</xsl:attribute>
                 </xsl:otherwise>
            </xsl:choose>
            <xsl:value-of select="$chg"/>&#160;(<xsl:value-of select="format-number($chg * 100 div $previous, '#0.0') "/>%)
        </div>
    </td>        
    </tr>
    </table>
    <div class="delayed">Quotes delayed by 20 minutes</div>
    <div class="refresh" onclick="document.location.reload(true);">Refresh<br />Quotes</div>
    <div class="moreQuote"><a href="/en/investors/information/4822.asp" target="_top">Additional data  <img src="/greenArrowBG.gif" /></a></div>
</div>
<!--page-level template-->
    </xsl:template>


    <xsl:template name="DisplayDateEN">
        <xsl:param name="strDate"/>
        <!--strDate is assumed to be in yyyymmdd format-->
        <!--year parse-->
        <xsl:variable name="strYear" select="substring($strDate,1,4)"/>
        <!--month parse and string map-->
        <xsl:variable name="intMonth">
            <xsl:value-of select="substring($strDate,5,2)"/>
        </xsl:variable>
        <xsl:variable name="strMonth">
            <xsl:if test="$intMonth='01'">January</xsl:if>
            <xsl:if test="$intMonth='02'">February</xsl:if>
            <xsl:if test="$intMonth='03'">March</xsl:if>
            <xsl:if test="$intMonth='04'">April</xsl:if>
            <xsl:if test="$intMonth='05'">May</xsl:if>
            <xsl:if test="$intMonth='06'">June</xsl:if>
            <xsl:if test="$intMonth='07'">July</xsl:if>
            <xsl:if test="$intMonth='08'">August</xsl:if>
            <xsl:if test="$intMonth='09'">September</xsl:if>
            <xsl:if test="$intMonth='10'">October</xsl:if>
            <xsl:if test="$intMonth='11'">November</xsl:if>
            <xsl:if test="$intMonth='12'">December</xsl:if>
        </xsl:variable>
        <!--day parse and remove trailing 0 if applicable-->
        <xsl:variable name="strDay">
            <xsl:choose>
                <xsl:when test="substring($strDate,7,1) = '0'">
                    <xsl:value-of select="substring($strDate,8,1)"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="substring($strDate,7,2)"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <!--display date as Dec. mm, YYYY-->
        <xsl:value-of select="concat($strMonth,' ',$strDay,', ',$strYear)"/>
    </xsl:template>

    <xsl:template name="DisplayDateFR">
        <xsl:param name="strDate"/>
        <!--strDate is assumed to be in yyyymmdd format-->
        <!--year parse-->
        <xsl:variable name="strYear" select="substring($strDate,1,4)"/>
        <!--month parse and string map-->
        <xsl:variable name="intMonth">
            <xsl:value-of select="substring($strDate,5,2)"/>
        </xsl:variable>
        <xsl:variable name="strMonth">
            <xsl:if test="$intMonth='01'">Janvier</xsl:if>
            <xsl:if test="$intMonth='02'">F&#233;vrier</xsl:if>
            <xsl:if test="$intMonth='03'">Mars</xsl:if>
            <xsl:if test="$intMonth='04'">Avril</xsl:if>
            <xsl:if test="$intMonth='05'">Mai</xsl:if>
            <xsl:if test="$intMonth='06'">Juin</xsl:if>
            <xsl:if test="$intMonth='07'">Juillet</xsl:if>
            <xsl:if test="$intMonth='08'">Ao&#251;t</xsl:if>
            <xsl:if test="$intMonth='09'">Septembre</xsl:if>
            <xsl:if test="$intMonth='10'">Octobre</xsl:if>
            <xsl:if test="$intMonth='11'">Novembre</xsl:if>
            <xsl:if test="$intMonth='12'">D&#233;cembre</xsl:if>
        </xsl:variable>
        <!--day parse and remove trailing 0 if applicable-->
        <xsl:variable name="strDay">
            <xsl:choose>
                <xsl:when test="substring($strDate,7,1) = '0'">
                    <xsl:value-of select="substring($strDate,8,1)"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="substring($strDate,7,2)"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <!--display date as Dec. mm, YYYY-->
        <xsl:value-of select="concat('Le ',$strDay,' ',$strMonth,' ',$strYear)"/>
    </xsl:template>

    <xsl:template name="DisplayTimeEN">
        <xsl:param name="strTime"/>
        <!--strTime is assumed to be in 00:00:00 format-->
        <xsl:if test="string-length($strTime) &gt; 0">
            <!--hour parse-->
            <xsl:variable name="intHour" select="substring($strTime,1,2)"/>
            <!--minute parse-->
            <xsl:variable name="intMinute" select="substring($strTime, 4,2)"/>
            <!--display time-->
            <xsl:choose>
                <xsl:when test="number($intHour) &lt; 12">
                    <xsl:variable name="strHour">
                        <xsl:choose>
                            <xsl:when test="number($intHour) &lt; 10">
                                <xsl:value-of select="substring($intHour, 2, 1)"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="$intHour"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:variable>
                    <xsl:value-of select="concat($strHour, ':', $intMinute, ' a.m')"/>
                </xsl:when>
                <xsl:when test="number($intHour) = 12">
                    <xsl:value-of select="concat($intHour, ':', $intMinute, ' p.m')"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:variable name="intNonMilitaryHour" select="number($intHour) - 12"/>
                    <xsl:variable name="strHour">
                        <xsl:choose>
                            <xsl:when test="number($intNonMilitaryHour) &lt; 10">
                                <xsl:value-of select="substring(string($intNonMilitaryHour), 1, 1)"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="$intNonMilitaryHour"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:variable>
                    <xsl:value-of select="concat($strHour, ':', $intMinute, ' p.m')"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:if>
    </xsl:template>

    <xsl:template name="DisplayTimeFR">
        <xsl:param name="strTime"/>
        <!--strTime is assumed to be in 00:00:00 format-->
        <xsl:if test="string-length($strTime) &gt; 0">
            <!--hour parse-->
            <xsl:variable name="intHour" select="substring($strTime,1,2)"/>
            <!--minute parse-->
            <xsl:variable name="intMinute" select="substring($strTime, 4,2)"/>
            <!--display time-->
        <xsl:value-of select="concat('&#224;&#160;', $intHour, 'h', $intMinute)"/>
        </xsl:if>
    </xsl:template>


</xsl:stylesheet>