<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:template match="/">
		<html>
			<head><title><xsl:value-of select="Log/@LogonName" /> - Message Log</title></head>
			<body>
				<xsl:for-each select="Log/Message">

					<!-- If it is the first message, insert a new conversation header -->
					<xsl:if test="position()=1">
						<xsl:call-template name="newConv" />
					</xsl:if>

					<!-- If we get to a new sessionid, insert a blank line and new conversation header -->
					<xsl:choose><xsl:when test="(preceding-sibling::Message[position()=1]/@SessionID != @SessionID)">
						<br />
						<xsl:call-template name="newConv" />
					</xsl:when>

					<!-- Else, if the username is not the same as last message, insert it -->
					<xsl:otherwise>
						<xsl:if test="(preceding-sibling::Message[position()=1]/From/User/@FriendlyName != From/User/@FriendlyName)">
							<xsl:call-template name="userName" />
						</xsl:if>
					</xsl:otherwise></xsl:choose>

					<!-- Output a timestamp and the message -->
					<div style="font-size: 70%; margin-left: 1.5%;">
						<span style="font family: tamoha; color: #000000;">
							(<xsl:value-of select="@Time"/>)
						</span>
						<span style="margin-left: 1.5%;">
							<xsl:attribute name="style">
								<xsl:value-of select="Text/@Style"/>
							</xsl:attribute>
							<xsl:value-of select="Text"/>
						</span>
					</div>
				</xsl:for-each>
			</body>
		</html>
	</xsl:template>

	<!-- Display the user name in bold -->
	<xsl:template name="userName">
		<span style="font-family: tahoma; color: #000000; font-weight: bold; font-size: 70%;">
			<xsl:value-of select="From/User/@FriendlyName"/> says:
		</span>
	</xsl:template>

	<!-- Display a new conversation header in a pretty div -->
	<xsl:template name="newConv">
		<div id="cstart" style="font-family: tahoma; font-size: 80%; color: #ffffff; background-color: #4488CC; border: 2px solid #2266AA; padding: 0.2%;">
			Conversation started
			<xsl:value-of select="@Date"/> at <xsl:value-of select="@Time"/>
		</div>
		<xsl:call-template name="userName" />
	</xsl:template>

</xsl:stylesheet>
        


