需要根据输入 xml 文件格式化日期
Need to format the date as per the input xml file
需要将日期格式从 123121(mmddyy) 更改为 12/31/2021(mm/dd/yyyy)
输入XML我有:
<section>
<Plans>
<Date>123121</Date>
</Plans>
</section>
<p>date: <keyword keyref="Cost:Date:date4"/></p>
XSL 我试过:
<xsl:template match="keyword[contains(@keyref, 'Cost:Date:date4')]">
<xsl:param name="section" as="element()" tunnel="yes">
<empty/>
</xsl:param>
<keyword keyref="Cost:Date:date4">
<xsl:call-template name="format_variable">
<xsl:with-param name="cur_keyref" select="@keyref"/>
<xsl:with-param name="cur_value"
select="$section//Plans/Date"/>
<xsl:with-param name="cur_format" select="'date4'"/>
</xsl:call-template>
</keyword>
</xsl:template>
<xsl:template name="format_variable">
<xsl:param name="cur_keyref" as="xs:string">MISSING</xsl:param>
<xsl:param name="cur_value" as="xs:string">MISSING</xsl:param>
<xsl:param name="cur_format" as="xs:string">MISSING</xsl:param>
<xsl:choose>
<xsl:when test="$cur_format = 'date4'">
<xsl:value-of select="format-dateTime($cur_value, '[M01]/[D01]/[Y0001]')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="concat('MISSING_FORMAT_', $cur_keyref, '_', $cur_value, '_[', $cur_format, ']')"
/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
当我尝试上面的代码时,它显示以下错误:
Invalid dateTime value "123121" (Too short)
请有人帮我得到输出上的 12/31/2021(mm/dd/yyyy)
值。
您正在尝试对无效的日期时间使用 format-dateTime()
函数。
你做不到的事情:
<xsl:value-of select="replace(Date, '(.{2})(.{2})(.{2})', '//20')"/>
请注意,这是假设您的所有日期都在 21 世纪。否则,您将需要额外的逻辑来识别世纪。
需要将日期格式从 123121(mmddyy) 更改为 12/31/2021(mm/dd/yyyy)
输入XML我有:
<section>
<Plans>
<Date>123121</Date>
</Plans>
</section>
<p>date: <keyword keyref="Cost:Date:date4"/></p>
XSL 我试过:
<xsl:template match="keyword[contains(@keyref, 'Cost:Date:date4')]">
<xsl:param name="section" as="element()" tunnel="yes">
<empty/>
</xsl:param>
<keyword keyref="Cost:Date:date4">
<xsl:call-template name="format_variable">
<xsl:with-param name="cur_keyref" select="@keyref"/>
<xsl:with-param name="cur_value"
select="$section//Plans/Date"/>
<xsl:with-param name="cur_format" select="'date4'"/>
</xsl:call-template>
</keyword>
</xsl:template>
<xsl:template name="format_variable">
<xsl:param name="cur_keyref" as="xs:string">MISSING</xsl:param>
<xsl:param name="cur_value" as="xs:string">MISSING</xsl:param>
<xsl:param name="cur_format" as="xs:string">MISSING</xsl:param>
<xsl:choose>
<xsl:when test="$cur_format = 'date4'">
<xsl:value-of select="format-dateTime($cur_value, '[M01]/[D01]/[Y0001]')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="concat('MISSING_FORMAT_', $cur_keyref, '_', $cur_value, '_[', $cur_format, ']')"
/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
当我尝试上面的代码时,它显示以下错误:
Invalid dateTime value "123121" (Too short)
请有人帮我得到输出上的 12/31/2021(mm/dd/yyyy)
值。
您正在尝试对无效的日期时间使用 format-dateTime()
函数。
你做不到的事情:
<xsl:value-of select="replace(Date, '(.{2})(.{2})(.{2})', '//20')"/>
请注意,这是假设您的所有日期都在 21 世纪。否则,您将需要额外的逻辑来识别世纪。