PlainText-xsl

This page belongs to http://blogofgreg.com/2013/05/08/making-colloquy-irc-logs-more-friendly/

<?xml version='1.0' encoding='iso-8859-1'?>
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
	<xsl:output omit-xml-declaration="yes" indent="no" />
	<xsl:param name="timeFormat" />

	<xsl:strip-space elements="*" />

	<xsl:template match="envelope | message">
		<xsl:text>[</xsl:text>
		<xsl:call-template name="short-time">
			<xsl:with-param name="date" select="message[1]/@received | @received" />
		</xsl:call-template>
		<xsl:text>] </xsl:text>
		<xsl:value-of select="sender | ../sender" />
		<xsl:text>: </xsl:text>
		<xsl:choose>
			<xsl:when test="message[1]">
				<xsl:value-of select="message[1]" />
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="." />
			</xsl:otherwise>
		</xsl:choose>
		<xsl:text>
</xsl:text>



		<xsl:apply-templates select="message[position() &gt; 1]" />
	</xsl:template>

	<xsl:template match="event">
		<xsl:text>[</xsl:text>
			<xsl:call-template name="short-time">
				<xsl:with-param name="date" select="@occurred" />
			</xsl:call-template>
		<xsl:text>] </xsl:text>
		<xsl:value-of select="message" />
		<xsl:if test="string-length( reason )">
			<xsl:text> (</xsl:text>
			<xsl:value-of select="reason" />
			<xsl:text>)</xsl:text>
		</xsl:if>
		<xsl:text>
</xsl:text>
	</xsl:template>

	<xsl:template name="short-time">
		<xsl:param name="date" /> <!-- YYYY-MM-DD HH:MM:SS +/-HHMM -->
		<xsl:variable name='hour' select='substring($date, 12, 2)' />
		<xsl:variable name='minute' select='substring($date, 15, 2)' />
		<xsl:choose>
		  <xsl:when test="contains($timeFormat,'H')">
		    <!-- 24hr format -->
		    <xsl:value-of select="concat($hour,':',$minute)" />
		  </xsl:when>
		  <xsl:otherwise>
		    <!-- am/pm format -->
		    <xsl:choose>
		      <xsl:when test="number($hour) &gt; 12">
			<xsl:value-of select="number($hour) - 12" />
		      </xsl:when>
		      <xsl:when test="number($hour) = 0">
			<xsl:text>12</xsl:text>
		      </xsl:when>
		      <xsl:otherwise>
			<xsl:value-of select="$hour" />
		      </xsl:otherwise>
		    </xsl:choose>
		    <xsl:text>:</xsl:text>
		    <xsl:value-of select="$minute" />
		    <xsl:choose>
		      <xsl:when test="number($hour) &gt;= 12">
			<xsl:text>pm</xsl:text>
		      </xsl:when>
		      <xsl:otherwise>
			<xsl:text>am</xsl:text>
		      </xsl:otherwise>
		    </xsl:choose>
		  </xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>

Leave a reply below!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s