Skip to content

Instantly share code, notes, and snippets.

@uniquelau
Created August 15, 2012 16:25
Show Gist options
  • Save uniquelau/3361385 to your computer and use it in GitHub Desktop.
Save uniquelau/3361385 to your computer and use it in GitHub Desktop.
navFiltered.xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:umb="urn:umbraco.library"
exclude-result-prefixes="umb"
>
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<!--
Title: Filtered Navigation
By: Laurence Gillian, www.voodoobytes.co.uk
Last updated: 14th July, 2012
-->
<!--
This macro looks at the 'layoutNavigation' property on all pages.
If the nodes property of layoutNavigation has a value set, it then outputs
a list item for the Node. Some additional logic is also in this part of the
template that adds a class of 'active' if the pages is being viewed.
TIP: IE8 does not support the CSS psuedo class of 'last-child', which would
allow us to select the 'last-child' in our CSS. If you have a requirement to style
the last element, simply add a test against position = last().
-->
<xsl:template match="/">
<xsl:variable name="filter" select="/macro/filter" />
<xsl:apply-templates select="$currentPage/ancestor-or-self::* [@level = 2]/descendant::* [@isDoc] [contains(layoutNavigation, $filter)]" />
</xsl:template>
<xsl:template match="* [@isDoc]">
<li>
<xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">
<xsl:attribute name="class">active</xsl:attribute>
</xsl:if>
<a href="{umb:NiceUrl(@id)}">
<xsl:value-of select="@nodeName" />
</a>
</li>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment