xslt-2.0 - 使用 xslt 2.0 将日期从 DD-MMM-YYYY 转换为 YYYY-MMM-DD
问题描述
我有一个日期格式为 (2019-Aug-19) (YYYY-MMM-DD) 的 XML。
我希望将其转换为 (2019-08-19) (YYYY-MM-DD)
听到是我所做的一个样本。但没有运气
<xsl:value-of select="format-dateTime(xs:dateTime(concat(date, T00:00:00Z')), '[D01]-[M01]-[Y0001]')"/>
解决方案
在这里你可能是另一种简单的方法:
XML:
<time>2019-Aug-19T00:00:00Z</time>
XSLT:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0">
<xsl:output method="text" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:variable name="dt" select="time"/>
<xsl:template match="/">
<xsl:value-of select="format-dateTime(xs:dateTime(replace($dt, substring-before(substring-after($dt,'-'),'-') ,format-number(index-of(('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov', 'dec'),lower-case(substring-before(substring-after(lower-case($dt),'-'), '-'))),'00'))),'[D01]-[M01]-[Y0001]')"/>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:transform>
结果:
19-08-2019
对于 YYYY-MM-DD,您可以执行以下操作:
<xsl:value-of select="format-dateTime(xs:dateTime(replace($dt, substring-before(substring-after($dt,'-'),'-') ,format-number(index-of(('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov', 'dec'),lower-case(substring-before(substring-after(lower-case($dt),'-'), '-'))),'00'))),'[Y0001]-[M01]-[D01]')"/>
结果:
2019-08-19
见链接:http: //xsltransform.net/nbiCsZm
推荐阅读
- docker - 为什么我不能将本地 Docker 映像推送到 Docker Hub 存储库?
- python - 从 Bokeh 中的数据表中单击选择的图表
- go - CI/CD 构建因 go -ldflags 失败
- magento - 所有产品都消失了,客户无法登录 magento 2.2.7
- ruby-on-rails - How do I preselect value in semantic_form_for
- php - WordPress Pagination Failing To Display
- .net - Difference between Nuget & SDK dependencies in .Net Core project
- haskell - 从记录中的字段派生实例
- python - 如何删除熊猫中具有特定条件的行
- progressive-web-apps - How do I uninstall a PWA with related files in Android Chrome browser