date - XSLT 1.0 (xsltproc) - 将日期格式从 yyyy-mm-ddthh-mm-ssz 转换为 yyyy-MM-dd HH:mm:ss.SSS Z
问题描述
输入 XML:
<testng-results>
<suite>
<test>
<class>
<test-method name="ABC" started-at="2019-03-13T21:26:52Z"></test-method>
<test-method name="XYZ" started-at="2019-03-13T21:27:15Z"></test-method>
</class>
</test>
</suite>
</testng-results>
我当前的 XSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<Suite>
<xsl:for-each select="testng-results/suite/test/class/test-method">
<test>
<xsl:attribute name="test_name">
<xsl:value-of select="@name" />
</xsl:attribute>
<start_time> </start_time>
</test>
</xsl:for-each>
</Suite>
所需的输出.XML:
<Suite>
<test test_name="ABC">
<start_time>2019-03-13 21:26:52.000 +0000 </start_time>
</test>
<test test_name="XYZ">
<start_time>2019-03-13 21:26:52.000 +0000 </start_time>
</test>
</Suite>
我必须从“started-at”值中获取日期并将其转换为 yyyy-MM-dd HH:mm:ss.SSS Z 格式以生成输出 xml。
我曾尝试使用 format-dateTime 函数,但 xsltproc (XSLT 1.0) 不支持它。
解决方案
AFAICT,您要做的就是用T
空格替换 ,并追加.000 +0000
而不是Z
:
<start_time>
<xsl:value-of select="translate(@started-at, 'TZ', ' ')"/>
<xsl:text>.000 +0000</xsl:text>
</start_time>
推荐阅读
- sql-server - 我想查找每个帐户在某个日期之前的最后一笔交易
- python-3.x - 根据它们之间的距离对线进行分组
- node.js - 使用 fetch 响应身份验证
- python - Python ValueError:无法将序列复制到数组
- sql - SQL Server,将多列连接到一行中
- kdb - KDB:如何将表中的列初始化为字符串
- http - 配置 nginx 以从单个服务器提供 HTTP 和 HTTPS 站点的麻烦
- git - 检查 gitignore 将跟踪哪些文件
- c# - C# - 一个接口,两个实现:如何将方法调用从一个实现重定向到另一个实现?
- r - 如何从函数中传递要在 tq_mutate (TidyQuant) 中选择的变量列表?