Page 1 of 1

Equivalent to greater than or less than test on strings

Posted: Thu Sep 24, 2009 3:25 am
by ra0543
In an XSL transformation I find

Code: Select all

<xsl:if test="@num>preceding-sibling::element/@num"> ... </xsl:if>
works fine as a test so long as the num attributes referenced have numerical values (e.g. when @num is 2 and the equivalent in the preceding sibling is 3, the result is false).

Is there some easy way of doing the same kind of test where the num attributes are, say, single lower-case letters of the alphabet i.e. match [a-z]? I should like to be able to do the same test but where the result is based on alphabetical order, e.g. when the first value is 'a' and the second is 'b' (i.e. to evaluate 'a'<'b' and get false) or vice versa ('b'>'a' to get true). Is there some alternative to the < and > operators that work with strings, or what can be done as a workround?

Re: Equivalent to greater than or less than test on strings

Posted: Thu Sep 24, 2009 4:11 pm
by sorin_ristache
Hello,

Use the compare function:

<xsl:if test="compare(@num, preceding-sibling::element/@num)"> ... </xsl:if>


Regards,
Sorin