Reputation:
I have an xml file with an xsl that I am trying to change the way the numbers are displayed. In the xml all the numbers are in the format 00:12:34
I need to remove the first 2 zeros and the colon and just display 12:34
I am not sure if I use a substring or a decimal format. I am pretty new to this so any help would be marvellous.
code in the xsl is as below:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table class="albumTable" cellpadding="0" cellspacing="0" border="0" width="100%">
<xsl:for-each select="track">
<tr>
<td><xsl:value-of select="duration"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Upvotes: 1
Views: 2635
Reputation: 338208
This is simple:
<xsl:value-of select="substring-after(duration, ':')" />
See: substring-after()
in the W3C XPath 1.0 spec.
This is a little more defensive (for the case that the "hours" part is unexpectedly not '00:'
):
<xsl:choose>
<xsl:when test="substring(duration, 1, 3) = '00:')">
<xsl:value-of select="substring-after(duration, ':')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="duration" />
</xsl:otherwise>
</xsl:choose>
Upvotes: 5