Last modified on 30 July 2006, at 09:12

Umbraco/Samples and Articles/XSLT/Sitemap

You could use the following XSLT to create a sitemap

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxml="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library"
        exclude-result-prefixes="msxml umbraco.library">

        <xsl:output method="html"/>

        <xsl:param name="currentPage"/>
        <xsl:variable name="maxLevelForSitemap" select="6"/>
        
        <xsl:template match="/">
                <div id="sitemap">
                        <xsl:call-template name="drawNodes">
                                <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level=1]"/>
                        </xsl:call-template>
                </div>
        </xsl:template>

        <xsl:template name="drawNodes">
                <xsl:param name="parent"/>
                <ul>
                        <xsl:for-each select="$parent/node">
                                <li>
                                        <a href="{umbraco.library:NiceUrl(@id)}">
                                                <xsl:value-of select="@nodeName"/>
                                        </a>
                                        <xsl:call-template name="drawNodes">
                                                <xsl:with-param name="parent" select="."/>
                                        </xsl:call-template>
                                </li>
                        </xsl:for-each>
                </ul>
        </xsl:template>
</xsl:stylesheet>