[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Changing boolean value of xsl:attribute at runtime
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|