473,396 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Sorting XML into a Hierarchy

I am generating an xml file off an employees table from a database to
use to databind a treeview to on a master page rather than call the db
every time the page loads.

I need to take this XML and sort it hierarchially so when the treeview
gets it, it shows all employees sorted with child nodes for employees
who report to them, etc.

I have never worked with XML but found enough online to assume an xsl
file would do the trick, provided it was written correctly.

What I have so far, thats not working, is this.


CODE TO GENERATE XML FILE FROM DB

DataSet SQLDataset = new DataSet("Employees");
SqlDataAdapter DBAdapter = new SqlDataAdapter("Select * FROM
tm2Employee", dbConn);
DBAdapter.Fill(SQLDataset);
SQLDataset.WriteXml(System.AppDomain.CurrentDomain .BaseDirectory +
"xml.xml", XmlWriteMode.WriteSchema);

//sort the XML Hierarchically
XslCompiledTransform xsltransform = new XslCompiledTransform();
xsltransform.Load(System.AppDomain.CurrentDomain.B aseDirectory +
"xsl.xsl");
xsltransform.Transform(System.AppDomain.CurrentDom ain.BaseDirectory +
"xml.xml", System.AppDomain.CurrentDomain.BaseDirectory + "xml2.xml2");
SAMPLE OF XML FILE GENERATED

<Employees>
<Table>
<LoginID>LEGAL\SmithJS</LoginID>
<EmployeeName>Smith, John</EmployeeName>
<EmployeeID>111111</EmployeeID>
<DOB>1980-07-23T00:00:00-04:00</DOB>
<AuthLevel>3</AuthLevel>
<ReportsTo>222222</ReportsTo>
</Table>
</Employees>

XSL FILE

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="ReportsTo" match="Employee" use="@ReportsTo"/>
<xsl:template match="/">
<Employee>
<xsl:for-each select="key('ReportsTo','0')">
<xsl:call-template name="recurse"/>
</xsl:for-each>
</Employee>
</xsl:template>
<xsl:template name="recurse">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:if test="key('ReportsTo',@id)">
<Employee>
<xsl:for-each select="key('ReportsTo',@id)">
<xsl:call-template name="recurse"/>
</xsl:for-each>
</Employee>
</xsl:if>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>


ENVIRONMENT

ASP.net 2.0
MSSQL Server 2000
Windows Server (unsure of version)

Aug 4 '06 #1
0 812

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Matt | last post by:
Hello, I would like to generate what I call an "overall class hierarchy" in UML automatically derived from my C++ code source. An example of what I seek: ...
10
by: Bob | last post by:
Sorting the following alphanumerics using myArray.sort(): 04-273-0001 04-272-0001 04-272-0003 04-272-0001 04-273-0001 Results in:
1
by: Dwight | last post by:
The place I'm working for has a need to sort an excel spread sheet the contains data from bill of materials. The spreadsheets can be up to 60,000 records. We had a process that did it in a macro...
3
by: krzysztof.konopko | last post by:
Hello! I want to design a class hierarchy with one base abstract class, let's say CBase. I have a predicate that every object in the class hierarchy must have a parent object of type from this...
2
by: L. Kliemann | last post by:
* Jerry Coffin <jcoffin@taeus.com>: My question was mostly out of curiosity. I've been working with C++ for about half a year now, and I came across several occasions where my first...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.