Click here to Skip to main content
11,490,003 members (58,672 online)
Click here to Skip to main content
Articles » Languages » XML » XSLT » Downloads
Add your own
alternative version

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

, 28 Feb 2002 179.7K 1.7K 46
A simple and generic way to use XSLT to generate a multi-level HTML tree menu from an XML source.
treefromxmlusingxslt.zip
TreeFromXMLUsingXSLT.xsl
<%@ Language=VBScript %>
<% option explicit %>
<HTML>
<HEAD>
<link type="text/css" rel="stylesheet" href="TreeFromXMLUsingXSLT.css" />
</HEAD>
<BODY>
<b>Development</b>
<%
	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";
		}
		else
		{
			//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;
		}
	}
}
</script>

</BODY>
</HTML>

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.

License

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

Share

About the Author

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

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