Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cascade Server Page Navigation
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!-- Import basic stylesheet -->
<xsl:import href="/_internal/stylesheets/globals"/>
<xsl:output indent="yes" method="xml"/>
<!--
This stylesheet should be used with the 'index-nav' block set to
"Start at the current page with folder hierarchy, and also include siblings"
User Metadata:
* Folders must have title or display names.
* Pages and folders must be marked to appear in the nav.
-->
<xsl:variable name="current-class">selected</xsl:variable>
<!-- Begin output -->
<xsl:template match="system-index-block">
<nav class="main-nav" id="nav" role="navigation">
<div class="menu">
<a class="open" href="#nav">Open Menu &#9660;</a>
<a class="close" href="#close">Close Menu &#9650;</a>
</div>
<div class="nav-items">
<ul>
<!-- Grab pages / folder-index pages -->
<xsl:apply-templates select="system-page[dynamic-metadata[name = 'nav']/value = 'Yes'] | system-folder[dynamic-metadata[name = 'nav']/value = 'Yes']"/>
</ul>
<div class="tech-search"><a href="/find-tech/index">Tech <span>Search</span></a></div>
</div>
</nav>
</xsl:template>
<xsl:template match="system-page | system-folder">
<xsl:if test="title">
<li>
<!-- This is messy, but the XML Cascade gives you is messy :-( -->
<!-- If this is *not* an index page, with @current -->
<xsl:if test="self::system-page[@current][name!='index']">
<xsl:attribute name="class"><xsl:value-of select="$current-class"/></xsl:attribute>
</xsl:if>
<!-- If this is a folder with @current and no child pages with @current -->
<xsl:if test="self::system-folder[@current][child::system-page[@current!='true']]">
<xsl:attribute name="class"><xsl:value-of select="$current-class"/></xsl:attribute>
</xsl:if>
<!-- If this is a folder with an index page with @current-->
<xsl:if test="self::system-folder[@current][child::system-page[@current='true'][name='index']]">
<xsl:attribute name="class"><xsl:value-of select="$current-class"/></xsl:attribute>
</xsl:if>
<!-- If this is the homepage -->
<xsl:if test="self::system-page[@current]/path='/index'">
<xsl:attribute name="class"><xsl:value-of select="$current-class"/></xsl:attribute>
</xsl:if>
<xsl:call-template name="page-link"/>
<xsl:if test="system-page[name!='index'][dynamic-metadata[name = 'nav']/value = 'Yes'] or system-folder[dynamic-metadata[name = 'nav']/value = 'Yes']">
<ul>
<xsl:apply-templates select="system-page[name!='index'][dynamic-metadata[name = 'nav']/value = 'Yes'] | system-folder[dynamic-metadata[name = 'nav']/value = 'Yes']"/>
</ul>
</xsl:if>
</li>
</xsl:if>
</xsl:template>
<!-- link output -->
<xsl:template name="page-link">
<a>
<xsl:attribute name="href">
<xsl:choose>
<xsl:when test="name(.) = 'system-page'">
<xsl:value-of select="path"/>
</xsl:when>
<xsl:when test="name(.) = 'system-folder'">
<xsl:value-of select="path"/>
<xsl:text>/index</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:attribute>
<xsl:choose>
<xsl:when test="display-name">
<xsl:value-of select="display-name"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="title"/>
</xsl:otherwise>
</xsl:choose>
</a>
</xsl:template>
</xsl:stylesheet>
<!--
Created by: JCN
Last updated: 2014-03-19
University of Missouri
Office of Web Communications
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment