我想将当前日期与开始日期和结束日期进行比较。
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>