首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在xslt中使用日期返回日期

如何在xslt中使用日期返回日期
EN

Stack Overflow用户
提问于 2019-10-08 05:55:53
回答 1查看 82关注 0票数 0

我想使用xslt中的日期返回当天。

投入:

代码语言:javascript
复制
<root>
  <date meetingdate="20 Jun 2019" meetingJetbetclubid="Forbury Park Harness"/>
</root>

产出应是:

代码语言:javascript
复制
<date-format>Tue:Forbury Park Harness</date-format>

尝试过的代码:

代码语言:javascript
复制
<xsl:template match="root/date">
  <date-format>
    <xsl:value-of select="concat(@meetingdate,':',@meetingJetbetclubid)" />
  </date-format>
</xsl:template>

我尝试过的代码并不像预期的那样是work9ing。我正在使用XSLT2.0

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-08 06:18:28

如果您的约会对象是YYYY DD格式,这将是一个微不足道的问题。那么你只需要把它格式化为每周一天。

实际上,您需要首先将给定的日期转换为YYYY DD:

代码语言:javascript
复制
<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>

Demohttps://xsltfiddle.liberty-development.net/gWEamKY

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58280844

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档