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

<!-- localized strings -->
<xsl:variable name='ColumnHeader_Time'>Time</xsl:variable>
<xsl:variable name='ColumnHeader_From'>Sender</xsl:variable>
<xsl:variable name='ColumnHeader_No'>Phone Number</xsl:variable>
<xsl:variable name='ColumnHeader_Loc'>Location</xsl:variable>
<xsl:variable name='ColumnHeader_Message'>Message</xsl:variable>

<!-- variables -->

<xsl:variable name='TableStyle'>font-family:Simsun; font-size:85%; text-align:left; vertical-align:top; table-layout:fixed</xsl:variable>
<xsl:variable name='GutterStyle'>width:2ex</xsl:variable>
<xsl:variable name='HeaderStyle'>border-bottom:1 solid black</xsl:variable>

<xsl:variable name='BlueStyle'>background-color:#e0edff</xsl:variable>
<xsl:variable name='GreenStyle'>background-color:#dfffd9</xsl:variable>


<xsl:template match="SMS">

    <html dir='ltr'>
    <head>
        <title>
            SMS of <xsl:value-of select="@PhoneModel"/>
        </title>
    </head>

    <body style='margin:0'>
        <table id='BodyTable' style="{$TableStyle}" cellspacing='0'>

            <col style="width:25ex;"/>
            <col style='{$GutterStyle}' />
            <col style="width:20ex;"/>
            <col style='{$GutterStyle}' />
            <col style="width:20ex;"/>
            <col style='{$GutterStyle}' />
            <col style="width:15ex;"/>
            <col style='{$GutterStyle}' />
            <col style="width:70ex;"/>

            <thead>
                <tr>
                    <th style="{$HeaderStyle}">
                        <xsl:value-of select="$ColumnHeader_Time"/>
                    </th>
                    <th/>
                    <th style="{$HeaderStyle}">
                        <xsl:value-of select="$ColumnHeader_From"/>
                    </th>
                    <th/>
                    <th style="{$HeaderStyle}">
                        <xsl:value-of select="$ColumnHeader_No"/>
                    </th>
                    <th/>
                    <th style="{$HeaderStyle}">
                        <xsl:value-of select="$ColumnHeader_Loc"/>
                    </th>
                    <th/>
                    <th style="{$HeaderStyle}">
                        <xsl:value-of select="$ColumnHeader_Message"/>
                    </th>
                </tr>
            </thead>

            <tbody style='vertical-align:middle'>
                     <xsl:apply-templates>
                         <xsl:sort select='@DateTime'  order='descending'/>
                     </xsl:apply-templates>
            </tbody>
        </table>        
    </body>
    </html>

</xsl:template>


<xsl:template match="Message">
    <tr height = "8">
        <xsl:call-template name="EmptyLine" />
        <td colspan="9"/>
    </tr>
    <tr>
        <xsl:call-template name="CommonMessageProcessing" />

        <td> <xsl:apply-templates select="Sender"/> </td>
        <td/>
        <td> <xsl:apply-templates select="PhoneNumber"/> </td>
        <td/>
        <td> <xsl:apply-templates select="Location"/> </td>
        <td/>
        <td>
            <span>
                <xsl:attribute name="style">
                    <xsl:value-of select="Text/@Style"/>
                </xsl:attribute>
                <xsl:value-of select="Text"/>
            </span>
        </td>
    </tr>
    <tr height = "8">
        <xsl:call-template name="EmptyLine" />
        <td colspan="9"/>
    </tr>
</xsl:template>

<xsl:template name="CommonMessageProcessing">
    <xsl:if test="(position() mod 2) = 1">
        <xsl:attribute name="style">
            <xsl:value-of select="$BlueStyle"/>
        </xsl:attribute>
    </xsl:if>
    <xsl:if test="(position() mod 2) = 0">
        <xsl:attribute name="style">
            <xsl:value-of select="$GreenStyle"/>
        </xsl:attribute>
    </xsl:if>

    <td> <xsl:value-of select="@DateTime"/> </td>
    <td/>
</xsl:template>

<xsl:template name="EmptyLine">
    <xsl:if test="(position() mod 2) = 1">
        <xsl:attribute name="style">
            <xsl:value-of select="$BlueStyle"/>
        </xsl:attribute>
    </xsl:if>
    <xsl:if test="(position() mod 2) = 0">
        <xsl:attribute name="style">
            <xsl:value-of select="$GreenStyle"/>
        </xsl:attribute>
    </xsl:if>
</xsl:template>


</xsl:stylesheet>
