Click to See Complete Forum and Search --> : xsl:if question


P_Aybara
July 31st, 2000, 03:50 PM
I'm trying to do a test such as the following in an XSL document:

if x-a < 10 then write 0

How would I go about doing this? This works fine for something simple like if x < 10:

xsl:if test="X[.$lt$10]"

but how would I go about doing something like:

xsl:if test="X-A[.$lt$10]"

(note that A is a fairly complicated expression which involves Xs, and I couldn't simplify X-A < 10 into a nice expression with just Xs on one side and constants on the other)

Sorry if that was confusing, not really sure how to explain it better than that. Any help is greastly appreciated. Thanks.


BTW, how do you get less than and greater than to appear in these posts so you can show HTML tags?

Lothar Haensler
August 1st, 2000, 02:17 AM
although I haven't done it, I think you should be able to do what you want by using the xsl.script functionality.
MSDN has a sample.
here is an excerpt:


&lt;xsl:if expr="even(this)"&gt;


&lt;xsl:script&gt;&lt;![CDATA[
function even(e) {
return absoluteChildNumber(e)%2 == 0;
}
]]&gt;&lt;/xsl:script&gt;

P_Aybara
August 1st, 2000, 09:20 AM
Thanks. I searched MSDN high and low to find some way of doing this. I did see the script functionality, but I never really thought about doing it that way, thanks!

Actually, I figured out another way to do the problem I needed this for (without requiring any if statements), but this will be useful information in the future I'm sure :)