Click here to Skip to main content
13,250,453 members (48,492 online)
Click here to Skip to main content
Articles » Languages » XML » XSLT » Downloads


46 bookmarked
Posted 28 Feb 2002

Using XSLT to generate a multi-level tree menu from XML

, 28 Feb 2002
A simple and generic way to use XSLT to generate a multi-level HTML tree menu from an XML source.
<%@ Language=VBScript %>
<% option explicit %>
<link type="text/css" rel="stylesheet" href="TreeFromXMLUsingXSLT.css" />
	dim xmlMenu
	dim xslMenu
	'Get the source XML
	set xmlMenu = server.CreateObject("Microsoft.XMLDOM")
	xmlMenu.async = false
	xmlMenu.load server.MapPath("TreeFromXMLUsingXSLT.xml")
	'Get the XSLT to transform the XML
	set xslMenu = server.CreateObject("Microsoft.XMLDOM")
	xslMenu.async = false
	xslMenu.load server.MapPath("TreeFromXMLUsingXSLT.xsl")
	'Transform the source XML using XSLT
	Response.Write xmlMenu.transformNode(xslMenu)
	set xmlMenu = nothing
	set xslMenu = nothing

<script language="jscript">
function ExpanderClicked()
	//Get the element that was clicked
	var ctlExpander = event.srcElement;
	var ctlSelectedEntry = ctlExpander.parentElement;
	//Get all the DIV elements that are direct descendants
	var colChild = ctlSelectedEntry.children.tags("DIV");
	if(colChild.length > 0)
		var strCSS;
		//Get the hidden element that indicates whether or not entry is expanded
		var ctlHidden = ctlSelectedEntry.all("hidIsExpanded");
		if(ctlHidden.value == "1")
			//Entry was expanded and is being contracted
			ctlExpander.innerHTML = "+&nbsp;";
			ctlHidden.value = "0";
			strCSS = "NotVisible";
			//Entry is being expanded
			ctlExpander.innerHTML = "-&nbsp;";
			ctlHidden.value = "1";
			strCSS = "IsVisible";
		//Show all the DIV elements that are direct children
		for(var intCounter = 0; intCounter < colChild.length; intCounter++)
			colChild[intCounter].className = strCSS;


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

MS le Roux
Web Developer
South Africa South Africa
I live in the Northern Suburbs of Cape Town (South Africa).

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171114.1 | Last Updated 1 Mar 2002
Article Copyright 2002 by MS le Roux
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid