Skip to content

Instantly share code, notes, and snippets.

@neilang
Created December 18, 2013 06:07
Show Gist options
  • Save neilang/8017956 to your computer and use it in GitHub Desktop.
Save neilang/8017956 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exslt="http://exslt.org/common"
xmlns:date="http://exslt.org/dates-and-times">
<xsl:output method="html" encoding="utf-8" indent="no" media-type="text/html" />
<xsl:template match="/">
<ul>
<xsl:apply-templates select="//api-v1-entities-event-item" />
</ul>
</xsl:template>
<xsl:template match="api-v1-entities-event-item">
<li>
<xsl:value-of select="title" />
<xsl:text>: </xsl:text>
<xsl:call-template name="FormatTime">
<xsl:with-param name="hour" select="date:hour-in-day(start-time)" />
<xsl:with-param name="minute" select="date:minute-in-hour(start-time)" />
</xsl:call-template>
<xsl:if test="end-time">
<xsl:text> - </xsl:text>
<xsl:call-template name="FormatTime">
<xsl:with-param name="hour" select="date:hour-in-day(end-time)" />
<xsl:with-param name="minute" select="date:minute-in-hour(end-time)" />
</xsl:call-template>
</xsl:if>
</li>
</xsl:template>
<xsl:template name="FormatTime">
<xsl:param name="hour">0</xsl:param>
<xsl:param name="minute">0</xsl:param>
<xsl:variable name="paddedMinute">
<xsl:if test="string-length($minute) = 1">
<xsl:text>0</xsl:text>
</xsl:if>
<xsl:value-of select="$minute" />
</xsl:variable>
<xsl:choose>
<xsl:when test="$hour &gt; 12">
<xsl:value-of select="($hour - 12)" />:<xsl:value-of select="$paddedMinute" /><xsl:text>pm</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$hour" />:<xsl:value-of select="$paddedMinute" /><xsl:text>am</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment