Author:
rainerborene
Version:
1.0
Release Date:
5 May 2010
Category:
String Operations

Description

This is a simple utility that converts seconds into a human-readable format in XSLT.

XSLT

View Raw
<?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>

Discuss this XSLT Utility

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details