I perfectly realize that this is VERY obscure :-)
XSLT1 has no function for the absolute value of a number
so...
((../../ref/@value - @value) < 0)) is false or true, casted to a number, false would be 0 and true would be 1
so the multiplier will be 1 for positive numbers and -1 for negative numbers, hence creating an absolut value
sorry, not the most comprehensible answer ever, but the only way to do this here
Main Topics
Browse All Topics





by: GertonePosted on 2009-10-29 at 11:30:17ID: 25696659
<xsl:for-each select="xml/values/any">
<xsl:sort select="(1 - 2 * ((../../ref/@value - @value) < 0)) * (../../ref/@value - @value)"/>
<xsl:copy-of select="."/>
</xsl:for-each>