将 xslt 中的日期格式从 YYYYMMDD 转换为 MM/DD/YYYY [英] Convert date format in xslt from YYYYMMDD to MM/DD/YYYY
本文介绍了将 xslt 中的日期格式从 YYYYMMDD 转换为 MM/DD/YYYY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 xml 文件中有日期,格式类似于
I am Having date in xml file in format like
YYYYMMDD
应用 xslt 转换我想将格式更改为
Applying the xslt transformation i want to change the format to
MM/DD/YYYY
.
例如,传入格式 - 20160513输出格式 - 05/13/2016
For example, Incoming format - 20160513 Output format - 05/13/2016
推荐答案
鉴于:
<date>20160513</date>
以下内容:
<xsl:template match="date">
<xsl:copy>
<xsl:value-of select="substring(., 5, 2)"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="substring(., 7, 2)"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="substring(., 1, 4)"/>
</xsl:copy>
</xsl:template>
将返回:
<date>05/13/2016</date>
这篇关于将 xslt 中的日期格式从 YYYYMMDD 转换为 MM/DD/YYYY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文