这些变量将为您提供日期(采用 ISO 8601 格式)和使用 XPath 1.0 表达式的时间:
<xsl:variable name="date">
<xsl:value-of select="substring-before(.,'T')"/>
</xsl:variable>
<xsl:variable name="time">
<xsl:value-of select="substring-before(substring-after(.,'T'),'.')"/>
</xsl:variable>
要将您的日期转换为 mm/dd/yyyy 格式,您可以将此模板添加到您的样式表中:
<xsl:template name="iso-to-mdy">
<xsl:param name="iso-date"/>
<xsl:variable name="year" select="substring($iso-date,1,4)"/>
<xsl:variable name="month" select="substring($iso-date,6,2)"/>
<xsl:variable name="day" select="substring($iso-date,9,2)"/>
<xsl:value-of select="$month"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="$day"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="$year"/>
</xsl:template>
而是像这样声明您的 date 变量,将您的 ISO 8601 日期作为参数传递:
<xsl:variable name="date">
<xsl:call-template name="iso-to-mdy">
<xsl:with-param name="iso-date" select="substring-before(.,'T')"/>
</xsl:call-template>
</xsl:variable>
然后您将获得所需格式的日期。要打印时间和日期之间的空格,您可以使用<xsl:text>:
<date>
<xsl:value-of select="$date"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$time"/>
</date>
将打印出来
<date>05/08/2014 08:01:26</date>
见XSLT Fiddle