我有一个这样的 xml
<event>
<name>Jazz festival</name>
<place>Rome</place>
<date>23/06/2014</date>
</event>
Run Code Online (Sandbox Code Playgroud)
我想通过 XSL 检查日期是在 2014 年 10 月 1 日之前还是之后。有人可以帮助我吗?
试试这个方法:
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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)