Skip to content

Instantly share code, notes, and snippets.

Created May 4, 2012 18:43
Show Gist options
  • Save anonymous/2596882 to your computer and use it in GitHub Desktop.
Save anonymous/2596882 to your computer and use it in GitHub Desktop.
<data>
<params>
<root>http://example.com</root>
<ds-toc-projects>
<item handle="project1">project1</item>
<item handle="project2">project2</item>
<item handle="project3">project3</item>
</ds-toc-projects>
<ds-toc-whatever>
<item handle="whatever1">whatever1</item>
<item handle="whatever2">whatever2</item>
<item handle="whatever3">whatever3</item>
</ds-toc-whatever>
<url-language>de</url-language>
</params>
<!-- this is your navigation DS -->
<navigation>
<page handle="projects" id="3">
<item lang="de" handle="projekte">Projekte</item>
<types>
<type>index</type>
<type>main</type>
</types>
</page>
<page handle="about" id="10">
<item lang="de" handle="ueber">Über</item>
<types>
<type>main</type>
</types>
</page>
<page handle="blog" id="1">
<item lang="de" handle="blog">Blog</item>
<types>
<type>main</type>
</types>
</page>
<page handle="contact" id="9">
<item lang="de" handle="kontakt">Kontakt</item>
<types>
<type>main</type>
</types>
</page>
</navigation>
</data>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dyn="http://exslt.org/dynamic"
extension-element-prefixes="dyn"
version="1.0" >
<!-- this is normally done in your master stylesheet -->
<xsl:apply-templates mode="navigation"/>
<!-- ensure lang var exists -->
<xsl:variable name="lang">
<xsl:choose>
<xsl:when test="/data/params/url-language">
<xsl:value-of select="$url-language"/>
</xsl:when>
<xsl:otherwise>en</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:template match="data" mode="navigation">
<nav>
<ul class="clear lang">
<xsl:apply-templates select="events/language-redirect"/>
</ul>
<ul class="clear main">
<xsl:apply-templates select="toc-pagesection/page"/>
</ul>
</nav>
</xsl:template>
<xsl:template match="page">
<xsl:variable name="subname">
<xsl:value-of select="concat('/data/params/ds-toc-', @handle)"/>
</xsl:variable>
<li>
<xsl:attribute name="id">
<xsl:value-of select="concat('navigation-', @handle)"/>
</xsl:attribute>
<a href="{$root}/{$lang}/{@handle}/" class="xhr"><xsl:value-of select="item"/></a>
<xsl:if test="dyn:evaluate($subname)">
<xsl:apply-templates select="dyn:evaluate($subname)" mode="sub">
<xsl:with-param name="parent" select="@handle"/>
</xsl:apply-templates>
</xsl:if>
</li>
</xsl:template>
<xsl:template match="*" mode="sub">
<xsl:param name="parent"/>
<ul class="sub clear">
<xsl:for-each select="item">
<li>
<a href="{$root}/{$lang}/{$parent}/{@handle}/" class="xhr"><xsl:value-of select="."/>
</a>
</li>
</xsl:for-each>
</ul>
</xsl:template>
<xsl:template match="language-redirect">
<xsl:for-each select="supported-languages/item">
<xsl:variable name="url">
<xsl:value-of select="concat($root, '/', @handle, substring($current-url, string-length($root)+4))"/>
</xsl:variable>
<li>
<a>
<xsl:attribute name="href">
<xsl:value-of select="$url"/>
</xsl:attribute>
<xsl:attribute name="class">
<xsl:text>lang</xsl:text>
<xsl:if test="@handle = $url-language">
<xsl:value-of select="' active'"/>
</xsl:if>
</xsl:attribute>
<xsl:value-of select="@handle"/>
</a>
</li>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment