如何在 XSLT 中计算数字的绝对值? [英] How can I calculate the absolute value of a number in XSLT?
本文介绍了如何在 XSLT 中计算数字的绝对值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有
<xsl:value-of select="DifferenceInDays" />
DifferenceInDays
有一个可以是负数或正数的值,我想显示它的绝对值.我该怎么做?
DifferenceInDays
has a value that can be a negative or a positive number, I want to display its absolute value. How can I do this?
推荐答案
在 XPath 1.0 中使用以下表达式:
$vNum*($vNum >=0) - $vNum*($vNum < 0)
如果此表达式嵌入在 XSLT (XML) 属性中,则必须对 <
字符进行转义:
In case this expression is embedded in an XSLT (XML) attribute, the <
character must be escaped:
$vNum*($vNum >=0) - $vNum*($vNum < 0)
在 XPath 2.0 (XSLT 2.0) 中使用 abs()
函数.
这篇关于如何在 XSLT 中计算数字的绝对值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文