Skip to content

Instantly share code, notes, and snippets.

@xpathr
Created May 10, 2012 14:40
Show Gist options
  • Select an option

  • Save xpathr/2653505 to your computer and use it in GitHub Desktop.

Select an option

Save xpathr/2653505 to your computer and use it in GitHub Desktop.
Format Duration by rainerborene
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
Note: Value paramater must be in seconds.
-->
<xsl:template name="format-duration">
<xsl:param name="value" />
<xsl:variable name="minutes" select="floor($value div 60)" />
<xsl:variable name="seconds" select="$value mod 60" />
<xsl:if test="$minutes">
<xsl:value-of select="$minutes" />
<xsl:text> minutes</xsl:text>
</xsl:if>
<xsl:if test="$minutes and $seconds">
<xsl:text> and </xsl:text>
</xsl:if>
<xsl:if test="$seconds">
<xsl:value-of select="$seconds" />
<xsl:text> seconds</xsl:text>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment