我有一个xsl的xml文件,我试图改变数字的显示方式.在xml中,所有数字的格式为00:12:34
我需要删除前2个零和冒号,然后显示12:34
我不确定我是使用子字符串还是十进制格式.我对此很陌生,所以任何帮助都会非常棒.
xsl中的代码如下:
<?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>
Run Code Online (Sandbox Code Playgroud)
这很简单:
<xsl:value-of select="substring-after(duration, ':')" />
Run Code Online (Sandbox Code Playgroud)
请参阅:substring-after()W3C XPath 1.0规范.
这有点防守(对于"小时"部分出乎意料的不是'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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2446 次 |
| 最近记录: |