How check which variable is greater in xsl?

2019-06-20 08:41发布

   <xsl:variable name="a">20</xsl:variable>
    <xsl:variable name="b">10</xsl:variable>

      <xsl:if test="($a) > ($b)">
        ------
  </xsl:if>

I getting error in the if condion..

标签: xslt
2条回答
啃猪蹄的小仙女
2楼-- · 2019-06-20 09:20

Try the following :

 <xsl:if test="$a &gt; $b">

Try using the character entities for > (&gt;) and < (&lt;) operators in expressions, otherwise some parsers think you are closing the tag early, or opening another.

查看更多
霸刀☆藐视天下
3楼-- · 2019-06-20 09:24

The example you posted should work. However, you should not that in your case both variables are of type string which could give surprising results where their length differs. The behaviour of the comparison operator on different datatypes is specified in the xpath spec on booleans.

To avoid this you could declare the variables using the select attribute or manually convert them to number for the comparison:

<xsl:variable name="a" select="20"/>
<xsl:variable name="b" select="10"/>
...
<xsl:if test="number($a) > number($b)">
</xsl:if>
查看更多
登录 后发表回答