我想将当前日期与开始日期和结束日期进行比较。
XML 是:
<forms>
<form id="11">
<start>somedate</start>
<end>someotherdate</end>
</form>
</forms>
我目前正在尝试:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ex="http://exslt.org/dates-and-times" extension-element-prefixes="ex" >
<xsl:choose>
<xsl:when test="end != ''
and start != ''
and ex:date(start) <= current-date()
and current-date() <= ex:date(end)">
<!-- Do Stuff -->
</xsl:when>
</xsl:choose>
我收到以下错误:
xmlXPathCompOpEval: function current-date not found
XPath error : Unregistered function
XPath error : Stack usage errror
<ul class="ccb_forms_ul"></ul>
最佳答案
假设您的日期采用 yyyy-mm-dd 格式(据我所知,它们来自您的其他问题),这应该适用于大多数 XSLT 1.0 处理器:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times"
extension-element-prefixes="date">
...
<xsl:for-each select="forms/form">
<xsl:variable name="today" select="translate(substring-before(date:date-time(), 'T'), '-', '')"/>
<xsl:variable name="start" select="translate(start, '-', '')"/>
<xsl:variable name="end" select="translate(end, '-', '')"/>
<xsl:if test="$start <= $today and $today <= $end">
<!-- in progress -->
</xsl:if>
关于date - XSLT 1.0 比较日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20342805/