С XSLT 1.0 используйте Jenny Tenison pure XSLT реализация из EXSLT date:difference()
.
В качестве подтверждения концепции эта таблица стилей:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times">
<xsl:import href="date.difference.template.xsl"/>
<xsl:template match="date">
<xsl:variable name="vDuration">
<xsl:call-template name="date:difference">
<xsl:with-param name="start" select="/test/@today" />
<xsl:with-param name="end" select="." />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="vDays"
select="substring-before(substring-after($vDuration,'P'),'D')"/>
<xsl:variable name="vHours"
select="substring-before(substring-after($vDuration,'T'),'H')"/>
<xsl:variable name="vMinutes"
select="substring-before(substring-after($vDuration,'H'),'M')"/>
<xsl:if test="$vDays">
<xsl:value-of select="concat($vDays,' days ')"/>
</xsl:if>
<xsl:if test="$vHours">
<xsl:value-of select="concat($vHours,' hours ')"/>
</xsl:if>
<xsl:if test="$vMinutes">
<xsl:value-of select="concat($vMinutes,' minutes ')"/>
</xsl:if>
<xsl:text>ago
</xsl:text>
</xsl:template>
</xsl:stylesheet>
С этим входом:
<test today="2011-03-09T15:00:00Z">
<date>2011-03-09T10:44:27Z</date>
<date>2011-02-09T10:44:27Z</date>
</test>
Выход:
4 hours 15 minutes ago
28 days 4 hours 15 minutes ago