关于我在level3中的xml
<IncorporationDate>
<CCYY>2016</CCYY>
<MM>04</MM>
<DD>21</DD>
</IncorporationDate>现在我需要将其显示为2016年4月21日
所以我尝试连接这个,并使用format-date,但在尝试格式化字符串时得到错误。
<xsl:variable name="incorpDate">
<xsl:value-of select="concat(//a:Identification/b:IncorporationDate/c:DD,'/',//a:Identification/b:IncorporationDate/c:MM,'/',//a:Identification/b:IncorporationDate/c:CCYY)"/>
</xsl:variable>然后
<xsl:value-of select="format-date($incorpDate, '[D] [MNn] [Y0001]')" />我尝试在整个节点上使用format-date
<xsl:value-of select="format-date(//a:Identification/b:IncorporationDate, '[D] [MNn] [Y0001]')" />我知道这可能很简单,但是xml/xslt不是我所知道的,我学习它是因为需要更改许多样式表。
发布于 2017-07-25 19:43:22
创建一个xs:date,然后格式化:
<xsl:template match="IncorporationDate">
<xsl:value-of select="format-date(xs:date(concat(CCYY, '-', MM, '-', DD)), '[D] [MNn] [Y0001]')"/>
</xsl:template>完整示例
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="IncorporationDate">
<xsl:value-of select="format-date(xs:date(concat(CCYY, '-', MM, '-', DD)), '[D] [MNn] [Y0001]')"/>
</xsl:template>
</xsl:transform>http://xsltransform.net/naZXpXm/1
https://stackoverflow.com/questions/45301971
复制相似问题