In my XSLT template, I want to do some conditional validation on ...">

Xslt param conditional check

I have:

<xsl:param name="SomeFlag" /> 

      

In my XSLT template, I want to do some conditional validation on SomeFlag. I am currently doing it like:

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

      

Is this how we rate the flag?

I am setting a parameter in C # as:

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

      

Any ideas?

+2


a source to share


2 answers


<xsl:if test="$SomeFlag = true">

      

This test if $SomeFlag

equals the string value of an element named "true" that is the first child of the current node.



You want :

<xsl:if test="$SomeFlag = true()">

      

+4


a source


I agree with Dimiter, but I have an addition:

In your case, you can simply use:

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

      



But I usually use 1 and 0 for boolean flags when the flags need to be evaluated in XSLT, especially when I am taking a value from an attribute or element content.

This allows me to test for conditions by casting off numbers (and then implicitly to booleans) instead of comparing against a string literal:

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

      

+3


a source







All Articles