XSL:如何比较两个日期?

时间:2015-09-02 14:15:09

标签: xslt

我有像这样的xml

<span class="glyphicon glyphicon-heart"></span> 

我想通过XSL检查日期是在2014年10月1日之前还是之后。 有谁可以帮助我?

2 个答案:

答案 0 :(得分:3)

以这种方式尝试:

XSLT 1.0

<xsl:template match="event">
    <xsl:variable name="date" select="10000 * substring(date, 7, 4) + 100 * substring(date, 4, 2) + substring(date, 1, 2)"/>
    <xsl:choose>
        <xsl:when test="$date > 20141001 ">
            <!-- code for dates later than 2014-10-01  -->
        </xsl:when>
        <xsl:otherwise>
            <!-- code for dates earlier than or equal to 2014-10-01 -->
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

XSLT 2.0

<xsl:template match="event">
    <xsl:variable name="date" select="xs:date(concat(substring(date, 7, 4), '-',  substring(date, 4, 2), '-', substring(date, 1, 2)))"/>
    <xsl:choose>
        <xsl:when test="$date gt xs:date('2014-10-01')">
            <!-- code for dates later than 2014-10-01  -->
        </xsl:when>
        <xsl:otherwise>
            <!-- code for dates earlier than or equal to 2014-10-01 -->
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

答案 1 :(得分:1)

谢谢。最后,我就这样做了

<xsl:variable name="data" select="concat(substring-after(substring-after(.,'/'),'/') , format-number( substring-before(substring-after(.,'/'),'/'), '00') , format-number( number( substring-before(.,'/')), '00') )"/>
<xsl:choose>
    <xsl:when test="$data &gt;  '20151018000000'">
        ...
    </xsl:when>
    <xsl:otherwise>
          ...
    </xsl:otherwise>
</xsl:choose>