xslt 2.0 compare current date to start and end date

余生长醉 提交于 2019-12-10 20:15:52

问题


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:


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>


来源:https://stackoverflow.com/questions/20319875/xslt-2-0-compare-current-date-to-start-and-end-date

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!