I have a bit of xslt in a macro that spits out nodes if they match certain criteria
<xsl:for-each select="$currentPage/node"> <xsl:sort select="data [@alias = 'date']" order="descending" data-type="text"/> <!--only draw something if we have access to it --> <xsl:if test="(umbraco.library:IsProtected(@id, @path) = false) or (umbraco.library:HasAccess(@id, @path) = true)"> protected=<xsl:value-of select="umbraco.library:IsProtected(@id, @path)"/><br/> access=<xsl:value-of select="umbraco.library:HasAccess(@id, @path)"/> </xsl:if> </xsl:for-each>
If it hits a node that is not protected it returns the following
protected=false
access=true
so far so good. If it hits a node that is protected, but to which my member does not have the correct group access it still displays the information
protected=true
access=false
which is wrong, why does it display that?
Also, if it hits a node which IS protected, but my member DOES have access, it doesn't display anything at all. Could this be something to do with my sort command?
You have to be very careful with true and false in XSLT - when used like that, the Processor will look for an element named <false> or <true> in the source tree - not what you want :-). You can use false() and true() instead, but a common idiom in XSLT is to use the not() function when testing for "something equals false()" - so something like this:
<xsl:iftest="not(umbraco.library:IsProtected(@id, @path)) or umbraco.library:HasAccess(@id, @path)">
...
</xsl:if>
(Of course, the reason they come out as "false" and/or "true" when using value-of is due to string-conversion)
Odd behaviour from umbraco.library.HasAccess
I have a bit of xslt in a macro that spits out nodes if they match certain criteria
If it hits a node that is not protected it returns the following
protected=false
access=true
so far so good. If it hits a node that is protected, but to which my member does not have the correct group access it still displays the information
protected=true
access=false
which is wrong, why does it display that?
Also, if it hits a node which IS protected, but my member DOES have access, it doesn't display anything at all. Could this be something to do with my sort command?
Sussed it, although I have no idea why.
I amended
to
and it worked. I'd love to know why that is though. Any ideas?
Hi Shaun,
You have to be very careful with true and false in XSLT - when used like that, the Processor will look for an element named <false> or <true> in the source tree - not what you want :-). You can use false() and true() instead, but a common idiom in XSLT is to use the not() function when testing for "something equals false()" - so something like this:
(Of course, the reason they come out as "false" and/or "true" when using value-of is due to string-conversion)
Hope this helps,
/Chriztian
Hi Chriztian
Thanks for explaining that for me. It makes perfect sense now :) I'll remember this next time I'm working with Booleans in xslt.
is working on a reply...