xslt 2.0将当前日期与开始和结束日期进行比较
问题描述:
我有以下输出:
<forms>
<form id="15">
<start>2013-12-09</start>
<end>2014-01-05</end>
</form>
</forms>
我想测试一下,看看当前日期是否等于或大于开始等于结束
I would like to test to see if current date is equal or greater to "start" and lesser or equal to "end"
我将如何进行测试?
我所想到的是:
<xsl:variable name="fstart">
<xsl:value-of select="start" />
</xsl:variable>
<xsl:variable name="fend">
<xsl:value-of select="end" />
</xsl:variable>
<xsl:choose>
<xsl:when test="$fstart >= currentdate xor currentdate <= $fend ">
<!-- do stuff -->
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
答
我相信它是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs">
...
<xsl:for-each select="forms/form">
<xsl:choose>
<xsl:when test="xs:date(start) <= current-date()
and
current-date() <= xs:date(end)">
<!-- in progress -->
</xsl:when>
<xsl:otherwise>
<!-- not started yet or already ended-->
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>