How can I calculate the absolute value of a number in XSLT?

前端 未结 4 1867
有刺的猬
有刺的猬 2020-12-10 03:57

I have

 

DifferenceInDays has a value that can be a negative or a posi

4条回答
  •  执笔经年
    2020-12-10 04:47

    In XPath 1.0 use the following expression:

       $vNum*($vNum >=0) - $vNum*($vNum < 0)
    

    In case this expression is embedded in an XSLT (XML) attribute, the < character must be escaped:

       $vNum*($vNum >=0) - $vNum*($vNum < 0)
    

    In XPath 2.0 (XSLT 2.0) use the abs() function.

提交回复
热议问题