tags:

views:

41

answers:

2

I have a:

<xsl:param name="SomeFlag" /> 

In my XSLT template, I want to do a conditional check on SomeFlag. Currently I'm doing it as:

<xsl:if test="$SomeFlag = true"> SomeFlag is true! </xsl:if>

Is this how we evaluate the the flag?

I'm setting the param in C# as:

xslarg.AddParam("SomeFlag", String.Empty, true);

Any ideas?

+2  A: 
<xsl:if test="$SomeFlag = true">

This tests if $SomeFlag is equal to the string value of the element named "true", which is the first child of the current node.

What you want is:

<xsl:if test="$SomeFlag = true()">
Dimitre Novatchev
+2  A: 

I agree with Dimitre, but have an addition:

In your case you can just use:

<xsl:if test="$SomeFlag"> SomeFlag is true! </xsl:if>    

But I usually use 1 and 0 for boolean flags when the flags are supposed to be evaluated in XSLT, especially when I take the value from an attribute or an element content.

This allow me to test conditions by casting to numbers (and then implicitly to boolean) instead of comparison to a string literal:

<xsl:if test="number($SomeFlag)"> SomeFlag is true! </xsl:if>
newtover
I never suggested comparing to a strung literal! Please, read my answer and understand it. Also, note that the OP sets the value to be tested from C# and uses a *boolean* value! So, your addition (while generally useful), does not answer the question.
Dimitre Novatchev
@Dimitre Novatchev: I do understand your answer, my idea is just to use 0 and 1 instead of boolean values. So that if the OP would serialize the value into the input tree instead of passing as parameter, the approach would stay the same.
newtover