XSLT 1.0 Compare Dates

后端 未结 1 1915
太阳男子
太阳男子 2021-01-13 16:30

I want to compare current date against a start date and end date.

XML is:


  
somedate
相关标签:
1条回答
  • 2021-01-13 17:07

    Assuming your dates are in yyyy-mm-dd format (as I understand they are from your other question), this should work with most XSLT 1.0 processors:

    <?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 &lt;= $today and $today &lt;= $end">
        <!-- in progress -->
    </xsl:if>
    
    0 讨论(0)
提交回复
热议问题