我有一个日期格式模板,我将日期值传递给格式为 YYYYMMDD
模板如下:
<xsl:template name="formatDate">
<xsl:param name="date" />
<xsl:variable name="year" select="substring($date, 1, 4)" />
<xsl:variable name="month" select="substring($date, 5, 2)" />
<xsl:variable name="day" select="substring($date, 7, 2)" />
<xsl:value-of select="concat($month, '/', $day, '/', $year)" />
</xsl:template>
这会将字符串 20131004 返回为 10/04/2013,这是正确的。
不过,我需要做的是,如果 $month 有前导零,则将其删除。例如,20130930 将是 09/30/2013,而我更喜欢 2013 年 9 月 30 日。
最有效的方法是什么?我可以在设置变量的值之前进行选择/何时,但我正在尝试使用 xslt 以正确的方式进行操作(我仍在尝试进入它,它正在出现)。
谢谢