xml - XSLT 中的字符串到日期转换返回未找到函数
问题描述
我正在尝试确定当前日期是否介于 XSLT/XPath 中的其他两个日期之间。我发现 xs:date(STRING) 将日期字符串转换为日期值,然后我可以与 current-date() 进行比较。
我的问题是在尝试这个时,我收到一个错误,说该函数不存在。dateTime 显然也不存在。这是我正在使用的名称空间的代码。
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/04/xpath-functions/"
xmlns:xs="http://www.w3.org/2001/XMLSchema/">
<xsl:if test = "fn:current-dateTime lt fn:date(EndDateActive)
and fn:current-dateTime gt fn:date(StartDateActive)">
结束日期和开始日期字符串的格式正确 afaik (yyyy-mm-dd),我也尝试了以下选项,它们都告诉我该函数不存在:
xs:date(EndDateActivate)
xsl:date(EndDateActivate)
fn:dateTime(EndDateActivate)
xs:dateTime(EndDateActivate)
xsl:dateTime(EndDateActivate)
解决方案
有几个问题:
fn:current-dateTime()
是一个函数。你错过了()
fn
命名空间是,http://www.w3.org/2005/xpath-functions
不是http://www.w3.org/2005/04/xpath-functions/
- 在 XSLT 中,您不需要使用
fn:
名称空间前缀。你可以使用current-dateTime()
- 在 XSLT 中,您不需要使用
- Schema 命名空间是
http://www.w3.org/2001/XMLSchema
, nothttp://www.w3.org/2001/XMLSchema/
(删除尾随/
) - 您正在尝试
xs:dateTime
比较xs:date
- 而不是
current-dateTime()
,使用current-date()
- 而不是
对您的命名空间声明进行以下调整:
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
和你的@test
:
<xsl:if test="fn:current-date() lt xs:date(EndDateActive)
and fn:current-date() gt xs:date(StartDateActive)">
</xsl:if>
推荐阅读
- android - Activity.getReferrer() 只获取应用 Uri,而不是 Web 引荐来源网址
- java - Spring Boot 同时更新 2 个类
- symfony - Symfony ChoiceType 启用或禁用 TextType
- android-studio - 即使我在模拟器上运行我的应用程序,Flutter Inspector 也会说“没有正在运行的应用程序”
- javascript - 如何在 for 循环(JS)中获得灵活的变量变量
- php - 每 2 周显示星期五的日期
- java - Ratpack 异步如何实现,它是如何工作的?
- regex - 正则表达式:如何为 HTML 模式值编写负正则表达式?
- perl - cpan "Set::IntervalTree" 或 "Algorithm::ExpectationMaximization" 不起作用 - 我在完整的错误日志下面解释
- oracle - oracle执行动态sql选择脚本并返回表格数据