Shanka Somasiri
Shanka Somasiri

Reputation: 631

How to get absolute value in xslt-1.0

Is there a way I can get the absolute value of a number in xslt-1.0? abs() function works but in xslt-2.0.

But I need a way the same abs() functionality but for xslt-1.0

e.g => input -1.5, expected output 1.5

Any advise would be much appreciated.

<xsl:value-of select="concat('-', abs(salesPrice/ns2:BelopFelt))"/>

possibly something to replace abs(salesPrice/ns2:BelopFelt)

Cheers

Upvotes: 0

Views: 806

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 117073

You can use:

translate($input, '-', '')

Or, if you prefer:

(2*($input > 0) - 1)*$input

Note that some XSLT 1.0 processors support the EXSLT math:abs() extension function.

Upvotes: 2

Related Questions