XSLT menu listing niveau 3 and 4

Topics: XSLT
Dec 30, 2010 at 7:40 PM

Need a little assistance with some XSLT again.

I'd like a menu that lists all pages on level 3, and when a page is selected it's level 4 children should be listed.
Basicly the standard multilevel submenu functionality, i my case level 3 and 4 in my page tree.

I just can't figure out what my functionscope should be to archieve this.

Can someone help out with an XSLT snippet and a tip :-)

Regards
  Martin

Coordinator
Jan 2, 2011 at 11:05 PM

The XSLT below is copied from the OmniCorp demo site, it does exactly what you request - if you install this demo you can examine it in more detail, the XSLT Function is titled "Omnicorp.Navigation.Sub".

Beside from the XSLT below, the function does a call to Composite.Pages.SitemapXml (default parameters).

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:in="http://www.composite.net/ns/transformation/input/1.0"
	xmlns="http://www.w3.org/1999/xhtml" 
	exclude-result-prefixes="xsl in">
	
	<!-- this variable is inserted on the "Function Calls" tab -->
	<xsl:variable name="root" select="/in:inputs/in:result[@name='SitemapXml']"/>
	
	<!-- this variable is local to the stylesheet :) -->
	<xsl:variable name="section" select="$root/Page/Page[@isopen='true']"/>
	
	<xsl:template match="/">
		<html>
			<head/>
			<body>
				<h1>
					<a href="{$section/@URL}">
						<xsl:value-of select="$section/@MenuTitle"/>
					</a>
				</h1>
				<ul>
					<xsl:apply-templates select="$section/Page"/>
				</ul>
			</body>
		</html>
	</xsl:template>
	
	<xsl:template match="Page[@MenuTitle!='']">
		<li>
			<a href="{@URL}">
				<xsl:if test="@iscurrent='true'">
					<xsl:attribute name="class">selected</xsl:attribute>
				</xsl:if>
				<span>
					<xsl:value-of select="@MenuTitle"/>
				</span>
			</a>
			<xsl:if test="@isopen='true' and Page">
				<ul>
					<xsl:apply-templates select="Page"/>
				</ul>
			</xsl:if>
		</li>
	</xsl:template>
	
</xsl:stylesheet>

 

Marcus :)