如何从xs:duration中提取毫秒?

问题描述 投票:0回答:2

我想从 XSLT 中的 xs:duration 中提取毫秒。

使用
format-dateTime()

XML:

<exposure_time>PT0.0032S</exposure_time>

XSLT:

<xsl:variable name="seconds" select="format-dateTime(exposure_time, '[s01].[f0001]')"/>

编译时出错:

Transformation failure: Error XPTY0004 at webpage.xslt#98
  Supplied value "PT0.0032S" is not a valid xs:dateTime
Error XPTY0004 at webpage.xslt#98
  Supplied value "PT0.0032S" is not a valid xs:dateTime

使用持续时间秒数()

seconds-from-duration(exposure_time)
返回
0
,我想得到
0.0032

xml xslt
2个回答
0
投票

在您的示例中,函数

seconds-from-duration()
应返回 0.0032 - 只不过结果的精度在某种程度上是由实现定义的。

我正在查看https://www.w3.org/TR/xpath-functions-31/的规范,据我所知(我可能错过了一些东西)第9.1.1节规定所有处理器必须支持毫秒精度或更高的日期和时间,但我没有看到类似的持续时间声明。

您实际使用的 XSLT 实现(和版本)是什么?


0
投票

正如其他人已经指出的那样,表达式:

seconds-from-duration(exposure_time) 

应该给你你需要的结果。

如果由于某种原因没有,您可以尝试使用

format-dateTime()
函数,但首先您需要将
dayTimeDuration
值转换为有效的
dateTime
。只需将其添加到具有空(午夜)时间组件的任意日期的
dateTime
即可完成此操作:

format-dateTime(xs:dateTime('2024-01-01T00:00:00') + xs:dayTimeDuration(exposure_time), '[s1].[f0001]')
© www.soinside.com 2019 - 2024. All rights reserved.