This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Changing boolean value of xsl:attribute at runtime? Can it be done ....


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.

-----Original Message-----
From: Joerg Heinicke [mailto:joerg.heinicke@gmx.de]
Sent: 05 April 2002 08:02
To: xsl-list@lists.mulberrytech.com
Subject: Re: [xsl] Changing boolean value of xsl:attribute at runtime?
Can it be done ....


Hello Brian,

you have the wrong approach. You are creating a div element with the
attribute value false. If one of the two conditions is fulfilled you replace
the attribute with its value true. But after this the attribute is "away",
it's only at the output tree, you can't access it again. So your code could
not work until now. The test on this attribute must always be false.

But why such a construct? Why not easily:

<xsl:if test="string(role) = '' or string(role) = $p_Authority">
        do anything
</xsl:if>

Another approach is using a variable instead of the attribute:

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

Hope this helps,

Joerg


> Hi,
>
> I've been trying to get the following code to work but I keep on
> encountering problems - is there a better way of doing it?
>
> I have a Menu node which contains an allowedUserRole node. This sub-node
may
> have multiple authority/role attributes. I pass in an authority parameter
to
> the XSL and only want to continue processing the Node if the
authority/role
> attribute is blank, or if one of the authority/role attributes matches the
> parameter. I have created an attribute to store the true/false, but when I
> test the attribute's value in the XSL, it is blank - although the correct
> value is appearing in the generated HTML???
>
> Any help/suggestions would be greatly appreciated.
>
> The XML looks as follows:
>
> <menus>
> <menu id="eNew">
>  <description>Main Menu</description>
>  <allowedUserRole>
>   <authority />
>  </allowedUserRole>
>  <contents>
>   <menu id="e1">
>    <description>Customers</description>
>    <allowedUserRole>
>     <authority>
>       <role>user2</role>
>     </authority>
>     <authority>
>       <role>manager</role>
>     </authority>
>    </allowedUserRole>
>   </menu>
>  </contents>
> </menu>
> </menus>
>
>
> The XSL code is:
>
> <xsl:template match="menu">
>  <div onselectstart="return false" ondragstart="return false">
>  <xsl:attribute name="allowedItem">false</attribute>
>
>  <xsl:for-each select="./allowedUserRole">
>   <xsl:for-each select="./authority">
>    <xsl:choose>
>     <xsl:when test="string(role) = ''">
>      <xsl:attribute name="allowedItem">true</xsl:attribute>
>     </xsl:when>
>     <xsl:otherwise>
>      <xsl:if test="string(role) = $p_Authority">
>       <xsl:attribute name="allowedItem">true</xsl:variable>
>      </xsl:if>
>     </xsl:otherwise>
>    </xsl:choose>
>   </xsl:for-each>
>  </xsl:for-each>
>
>  <xsl:choose>
>  <xsl:when test="allowedItem = 'true'">
> .....continue processing node


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


**********************************************************************
Privileged, confidential and/or copyright information may be contained
in this e-mail. This e-mail is for the use only of the intended
addressee. If you are not the intended addressee, or the person
responsible for delivering it to the intended addressee, you may not
copy, forward, disclose or otherwise use it or any part of it in any
way whatsoever. To do so is prohibited and may be unlawful.

If you receive this e-mail by mistake please advise the sender
immediately by using the reply facility in your e-mail software.

Orygen (Ireland) Limited may monitor the content of e-mails sent and
received via its network for the purposes of ensuring compliance with
its policies and procedures.

This message is subject to and does not create or vary any contractual
relationship between Orygen (Ireland) Limited and you.
**********************************************************************



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]