I have
<xsl:value-of select="DifferenceInDays" />
DifferenceInDays
can be negative or positive, I want to display it as positive. How can I do this?
I have
<xsl:value-of select="DifferenceInDays" />
DifferenceInDays
can be negative or positive, I want to display it as positive. How can I do this?
In XPath 1.0 use the following expression:
In case this expression is embedded in an XSLT (XML) attribute, the
<
character must be escaped:In XPath 2.0 (XSLT 2.0) use the
abs()
function.Some of the answers are complicating life way too much for XSLT 1.0 it's actually much simpler. Using the number formatting you can define a structure for Positive and Negative numbers, the default negative is
-0
however you can define your own.The above code will show the absolute value of Difference in Days just by using the provided formatting function.
diffInDays * (1 - 2*(diffInDays < 0))
This can be achieved using the xpath abs function.