如何在xslt中使用日期返回日期
我想在xslt中使用日期返回日期 输入:如何在xslt中使用日期返回日期,xslt,Xslt,我想在xslt中使用日期返回日期 输入: <root> <date meetingdate="20 Jun 2019" meetingJetbetclubid="Forbury Park Harness"/> </root> 输出应为: <date-format>Tue:Forbury Park Harness</date-format> Tue:Forbury公园线束 试用代码: <xsl:template mat
<root>
<date meetingdate="20 Jun 2019" meetingJetbetclubid="Forbury Park Harness"/>
</root>
输出应为:
<date-format>Tue:Forbury Park Harness</date-format>
Tue:Forbury公园线束
试用代码:
<xsl:template match="root/date">
<date-format>
<xsl:value-of select="concat(@meetingdate,':',@meetingJetbetclubid)" />
</date-format>
</xsl:template>
我尝试过的代码没有按预期工作。我使用的是XSLT 2.0,如果您的日期是YYYY-MM-DD格式,这将是一个小问题。然后您只需要将其格式化为星期几 实际上,您需要从将给定日期转换为YYYY-MM-DD开始:
<xsl:template match="date">
<xsl:variable name="date-parts" select="tokenize(@meetingdate, ' ')"/>
<xsl:variable name="m" select="index-of (('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), $date-parts[2])"/>
<xsl:variable name="date" select="xs:date(concat($date-parts[3], format-number($m, '-00'), format-number(number($date-parts[1]), '-00')))" />
<date-format>
<xsl:value-of select="format-date($date, '[FNn,*-3]:')" />
<xsl:value-of select="@meetingJetbetclubid" />
</date-format>
</xsl:template>
演示: