Reputation: 2014
I have a menu generated in a Umbraco macro:
<xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevel and (umbraco.library:IsProtected(@id, @path) = false() or umbraco.library:HasAccess(@id, @path) = true())] ">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:for-each>
In that foreach, I would like a if-statement that only accepts a certain doctype, and generates the respective li/a tags and inserts a param from that doctype in the href. Only thing I can think of, is something like this:
<xsl:if test="$currentPage/Redirect">
<li>
<a href="{$urlRedirect)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:if>
Where Redirect
is the doctype, and $urlRedirect
is the param.
Bear with me, this is my first day learning XSLT
UPDATE: Heres the complete code so you can see it in context:
<xsl:template match="/">
<!-- The fun starts here -->
<!-- update this variable on how deep your navigation should be -->
<xsl:variable name="maxLevel" select="5"/>
<xsl:variable name="minLevel" select="4"/>
<xsl:choose>
<xsl:when test="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevel and (umbraco.library:IsProtected(@id, @path) = false() or umbraco.library:HasAccess(@id, @path) = true())] ">
<ul>
<xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevel and (umbraco.library:IsProtected(@id, @path) = false() or
umbraco.library:HasAccess(@id, @path) = true())] ">
<!-- Here is where I want my if/else logic -->
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:for-each>
</ul>
</xsl:when>
<xsl:otherwise>
<ul>
<xsl:for-each select="$currentPage/../* [@level > 3 and @isDoc and string(umbracoNaviHide) != '1' and (umbraco.library:IsProtected(@id, @path) = false() or umbraco.library:HasAccess(@id, @path) = true())] ">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:for-each>
</ul>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Upvotes: 1
Views: 2402
Reputation: 6184
you can do it like this:
<xsl:template match="/">
<!-- The fun starts here -->
<!-- update this variable on how deep your navigation should be -->
<xsl:variable name="maxLevel" select="5"/>
<xsl:variable name="minLevel" select="4"/>
<xsl:choose>
<xsl:when test="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevel and (umbraco.library:IsProtected(@id, @path) = false() or umbraco.library:HasAccess(@id, @path) = true())] ">
<ul>
<xsl:apply-templates select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevel and (umbraco.library:IsProtected(@id, @path) = false() or umbraco.library:HasAccess(@id, @path) = true())]" />
</ul>
</xsl:when>
<xsl:otherwise>
<ul>
<xsl:for-each select="$currentPage/../* [@level > 3 and @isDoc and string(umbracoNaviHide) != '1' and (umbraco.library:IsProtected(@id, @path) = false() or umbraco.library:HasAccess(@id, @path) = true())] ">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:for-each>
</ul>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="*">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:template>
<xsl:template match="Redirect">
<li>
<a href="{urlRedirect}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:template>
Upvotes: 2