[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Generate Hierarchical Tree from non-hierarchical XML

Subject: RE: Generate Hierarchical Tree from non-hierarchical XML
From: Ben Robb <Ben@xxxxxxxxxx>
Date: Thu, 17 Aug 2000 18:42:15 +0100
RE: Generate Hierarchical Tree from non-hierarchical XML

<xsl:template match="employees">
	<table><xsl:apply-templates select="employee[manager = '']

<xsl:template match="employee">
	<tr><td width="150"></td><td>
		<xsl:value-of select="name" />
		<xsl:if test="../employee[manager != current()/id]">
select="../employee[manager = current()/id] ">
					<xsl:sort select="id"/>

Key points:

1) I've wrapped it in nested tables to make it easier for me to spot where
the element is being called.

2) The key to this working is the apply-templates in the employee template.
Since we are selecting all of the employees which match the manager value to
the current id value, we are only nesting the ones we want. Finally, we are
sorting by id; this is as you wanted in your output. The use of
apply-templates also allows for an infinite depth of recursion.

Hope this helps,


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.