需要從輸入的 xml 元素中獲取 20 天之前。
輸入 xml 我有(年-月-日):
<section>
<Plans>
<Date>2022-01-01</Date>
</Plans>
</section>
<p>20 days back 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:variable name="format" select="replace($cur_value, '(.{4})-(.{2})-(.{2})', '$2/$3/$1')"/>
<xsl:value-of select="$format - xs:dateTime('P20D')"/>
</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 "P20D" (Non-numeric year component)
預期輸出為:
20 days back date: 12/12/2021
uj5u.com熱心網友回復:
FWIW,我相信你把這個問題復雜化了。輸入 XML 中的日期為 YYYY-MM-DD 格式;您需要做的就是從給定日期中減去 20 天的持續時間 - 請參閱此處的演示:https : //xsltfiddle.liberty-development.net/6qaCymJ
uj5u.com熱心網友回復:
我想你想用例如減去 dayTimeDuration <xsl:value-of select="$format - xs:dayTimeDuration('P20D')"/>。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/355821.html
上一篇:java.time.format.DateTimeParseException:無法在索引2處決議文本“103545”
