xslt 2.0 compare current date to start and end dat

2019-07-23 16:37发布

I have the following output:

 <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"

How would I go about testing for this?

What I had in mind is:

<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>

1条回答
Explosion°爆炸
2楼-- · 2019-07-23 17:16

I believe it goes like this:

<?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) &lt;= current-date() 
                    and 
                    current-date() &lt;= xs:date(end)">
        <!-- in progress -->
    </xsl:when>

    <xsl:otherwise>
        <!-- not started yet or already ended-->
    </xsl:otherwise>
  </xsl:choose>
</xsl:for-each>
查看更多
登录 后发表回答