Re: [xsl] Changing boolean value of xsl:attribute at runtime? Can it be done ....

Subject: Re: [xsl] Changing boolean value of xsl:attribute at runtime? Can it be done ....
From: "Joerg Heinicke" <joerg.heinicke@xxxxxx>
Date: Sat, 6 Apr 2002 03:29:43 +0200
> Hi Joerg,
>
> Thanks for the tips, we used the first one and it worked a treat .... one
> small question about xsl:if statements thought,
>
> when we use:
>
> <xsl:if test="$allowedItem = 'true'">
>
> the if statement fails even when allowedItem is equal to 'true', but if we
> use:
>
> <xsl:if test="$allowedItem != ''">
>
> the if statement works. In our situation, the only value of allowedItem
can
> be either null or true.
>
> If you have any ideas can you drop a mail .... thanks again.

I don't have any idea why it is so ;-) Or only a little one.

> <xsl:template match="menu">
>     <xsl:variable name="allowedItem">
>         <xsl:choose>
>             <xsl:when test="string(role) = '' or string(role) =
> $p_Authority">true</xsl:when>
>             <xsl:otherwise>false</xsl:otherwise>
>         </xsl:choose>
>     </xsl:variable>
>     <xsl:if test="$allowedItem = 'true'">
>         do anything
>     </xsl:if>
> </xsl:template>

The only valid values for $allowedItem are the strings 'true' and 'false'.
If you test on these strings in the way I did it, it should work. One thing
I can imagine (my little idea): You wrote the XSL-code a little bit
different:

<xsl:when test="...">
    true
</xsl:when>

This means you have additional whitespaces and linebreaks at your
'true'-string, so the test will fail. You can change it to my above code:
<xsl:when test="...">true</xsl:when>. Or using xsl:text:

<xsl:when>
    <xsl:text>true</xsl:text>
</xsl:when>

Or when testing on $allowedItem you can use normalize-space(), which removes
the whitespaces and linebreaks: <xsl:if test="normalize-space($allowedItem)
= 'true'">.

I don't have more ideas.

Joerg


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread