开发者

xslt param conditional check

开发者 https://www.devze.com 2022-12-29 02:02 出处:网络
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:

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?


<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()">


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消