Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在xslt中使用日期返回日期_Xslt - Fatal编程技术网

如何在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

我想在xslt中使用日期返回日期

输入:

<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>


演示