开发者

XSLT Date Comparisons

开发者 https://www.devze.com 2023-04-10 16:55 出处:网络
<xsl:variable name=\"date1\" select=\"2011-10-05\"/> <xsl:variable name=\"date2\" select=\"2011-10-05\"/>
<xsl:variable name="date1" select="2011-10-05"/>
<xsl:variable name="date2" select="2011-10-05"/>
<xsl:variable name="date3" select="2011-10-06"/>

<xsl:if test="$date2 = $date1 or $date2 &lt; $date1">
  ..do something
</xsl:if>

<xsl:if test="$date3 = $date1 or $date3 &gt; $date1">
 开发者_开发百科.. do something
</xsl:if>

Both should evaluate true, but the second if doesn't. For the life of me I can't comprehended why!

In the actual transform the dates themselves are being drawn from an XML document but debugging through VS2010 i can see the values are as above.

Must be something fairly fundamental i'm doing wrong - any help would be brilliant!


I tried this in Oxygen/XML... select="2011-10-05 is being interpreted as an arithmetic expression, giving the value 1996 (2011 minus 10 minus 5) and "2011-10-06" is intrepreted as 1995.

What you want is

<xsl:variable name="date1" select="'2011-10-05'"/>
<xsl:variable name="date2" select="'2011-10-05'"/>
<xsl:variable name="date3" select="'2011-10-06'"/>

Note the extra single quotes.

From the XSLT 1.0 Specification:

If the variable-binding element has a select attribute, then the value of the attribute must be an expression and the value of the variable is the object that results from evaluating the expression.

0

精彩评论

暂无评论...
验证码 换一张
取 消