Sort XML Into 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.


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

 //sort the XML Hierarchically
XslCompiledTransform xsltransform = new XslCompiledTransform();
xsltransform.Load(System.AppDomain.CurrentDomain.BaseDirectory +
xsltransform.Transform(System.AppDomain.CurrentDomain.BaseDirectory +
"xml.xml", System.AppDomain.CurrentDomain.BaseDirectory + "xml2.xml2");


    <EmployeeName>Smith, John</EmployeeName>


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

MSSQL Server 2000
Windows Server (unsure of version)

8/4/2006 1:42:55 PM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 23

It looks like you got a reply on this post in the microsoft.public.xml =
group--did that answer your question?

Greg Collins [Microsoft MVP]
Visit Brain Trove ( )

8/6/2006 4:23:45 AM

Similar Artilces:

Hi, is it possible to use variable for sorting? Something like: declare @sort varchar(10) SET @sort='column1 DESC' SELECT ROW_NUMBER() OVER (ORDER BY @sort)AS rowId, * FROM table Is dynamic SQL only option? Thank you, Simon On 15/04/2010 11:28, simon wrote: > Hi, > > is it possible to use variable for sorting? > > Something like: > > declare @sort varchar(10) > SET @sort='column1 DESC' > > SELECT ROW_NUMBER() OVER (ORDER BY @sort)AS rowId, * FROM table > > Is dynamic SQL only option? You can use CASE to he...

How to sort account list?
I'm using MS Money 2004 Small Business. In the account list, my accounts are catagorized by and in this order: - bank accounts - credit accounts - investment accounts - loans and liabilities - asset accounts TOTAL BALANCE In the above view, I cannot easily determine totals for assets and liabilities. The following view does this. - bank accounts - investment accounts - asset accounts SUBTOTAL -loans and liabilities SUBTOTAL TOTAL BALANCE How do I get the above view? Thanks, Brett I don't use Small Business. But you can run a Net Worth report to get total assets and ...

Where's the Sort by New Message option?
Not sure when the layout of the newsgroups changed but I can't seem to find the ability to sort by new message in a thread instead of sorting by just the original thread date. That was hugely helpful as I could follow along and see what threads were still active. If you're gonna hang around in the newsgroups (any newsgroups), you may want to start using a newsreader. Microsoft Outlook Express can do it for you. Saved from a previous post: You may want to connect to the ms newsserver directly: If you have Outlook Express installed, try clicking on these links (or copy and paste i...

Row names will not move with sort
Each row in my summary table in Sheet1 is hyperlinked to a corresponding table in Sheet2 with additional details. I need to move the rows in my summary table (Sheet1) and preserve the links to and from the details tables (Sheet2). I found that I can move rows in Sheet1 with cut & insert and the hyperlinks are maintained. I can travel from a row in summary table (Sheet1) to details table (Sheet2) and back, even after the corresponding row (Sheet1) was moved. But if I sort the rows in Sheet1 the links from Sheet2 back to corresponding rows in Sheet1 lead to presorted locations. Apparen...

sorts not sorting
OK- Thanks to everyones help I now i have a list i can work with... but there are a few problems.... the zips are all 5 digit and now i have to sort them... the problem is, THEY WONT SORT CORRECTLY!!!!!!! The numbers are not in order... some are but a lot are not... is there anyway to fix this???? i need to sort them by zip code but cant seem to get them to do it correctly.. any ideas??? ------------------------------------------------ ~~ Message posted from ~~ View and post usenet messages directly from You are going to be far better of...

XML Digital Signatures
Hi everyone I've been doing my best to understand the specifics of implimentating XML Digital Signatures, but I seem to be missing a fundamental concept. Let me start with a description of the problem I am trying to solve. In my application, people send an XML file that contains data for loans. The application then takes that data and performs various calculations returning the results in an XML file that combines both the initial data and the calculated data. The problem here is that the people who recieve this XML then want to send this to another group for the purpose of selli...

import- number- sort?
I imported this data into a spread sheet- I tried to format it to number, but when I sort it- I get : 37.08 4.33 4.79 4.8 42.56 5.94 Whats up with this? Thanks Brent Hi Brent, Install the TrimAll macro, select the column and invoke the macro from Alt+F8 Directions to install and use a macro at I expect that you have spaces or CHAR(128) "Required Blank" characters in you data you can check is =LEN(A1) --- HTH, David...

Form elements into xml
Hi, I've been asked to write a generic function/class to scan posted forms and generate a xml document as follow: 1. page1.aspx (or asp) posts to process.aspx 2. process.aspx calls a function that scans the form(s) and generates a xml from elements and values(entered by user) of the form. I thought it might be better to ask you guys and you may know a function or class in the framework that already does this and put me on the right track. Thanks for you time Regards Mehdi ...

sorting macro #3
I need to sort on 8 cells in a row and on 1500+rows. I can do it one at a time but I know there must be an easier way. Can ANYONE HELP? C3:J3 I need these cells sorted and then down to C1532:J1532 I did create a macro to sort after I selected them but still one at a time. Does it have to be a macro? I can edit a macro but don't really know how to program them. Yes, it has to be a macro. The following should do it. This macro loops through all the entries in Column C, and in each row it sorts the values in Columns C:J. HTH Otto Sub SortRows() Dim rColC As Range Dim i As...

Sorting checking register
How do i sort my check register in Money 2004 Deluxe so that uncleared transactions appear below cleared transactions? In Quicken i could click on the column to provide that sort. In, Dean wrote: >How do i sort my check register in Money 2004 Deluxe so >that uncleared transactions appear below cleared >transactions? In Quicken i could click on the column to >provide that sort. You don't. Available choices are chosen by clicking View at the top of the register. ...

Can we sort a form and also be able to enter new records.
Hi, It is possible to sort the data on a form and also be able to enter new and edit the existing records in it. Cheers! On Tue, 15 Jan 2008 15:41:16 -0800 (PST), Rex wrote: > Hi, > > It is possible to sort the data on a form and also be able to enter > new and edit the existing records in it. > > Cheers! I assume you mean "Is it". The form sort order has nothing to do with editing or adding new records, so the answer is yes. If you cannot edit or add new records, make sure the form's record source, if it is a query, is updateable. Some queries are not. O...

XML query
Hi I am new to using XML, and have a bit of an issue. How do I define how the XML file looks when I export a query from Access? On Sep 12, 4:50 pm, wrote: > Hi I am new to using XML, and have a bit of an issue. How do I define > how the XML file looks when I export a query from Access? XML is a markup language: That means, it is a plain text file, it uses tags. When you export a query from Access 2003 to XML, several files with different purpose can be generated. 1. A file with .xml exten...

using addrress books to sort incoming mail
I use address books to sort incoming mail. An odd thing: depending on how the sender's name comes across, it doesn't get caught by the filter (amd moved to the "Family Mail" Folder I have set up. for example: my mom and dad's email (from comes as from that address. However, in my contacts, they are listed by their names: John and Mary Smith, with as their email address and John and Mary Smith as the display name. What have I done wrong? TIA 1. The big ONE - failed to post your version of Outlook. Rules operate at ...

Unmerge so I can sort
I coy/pasted data into Excell and when I try to sort it I get "This operation requires merged sells to be identically sized". I understadn the work around in KB but how do I find which sells are merged? I wouldn't bother looking. I'd just remove all the merged cells from the range to sort. Select that range format|cells|alignment tab uncheck the merge cells box But if you wanted to search, you can do it via process of elimination. Select a range, format|cells|alignment tab. If that merge cells box is checked, then the whole selection is merged. If it's grey, t...

sorting issue
Hi, When a range of columns are highlighted and a sort is performed on only one column empty cells above the sort display first. How can this be prevented. I know when there is data in any of the other column but not on the column being sorted this will happen. Any thoughts? Pat Are you sure the cells are really empty? They don't contain spaces or even formulas that evaluate to "". (Even formulas converted to values that returned "")? Pat wrote: > > Hi, > > When a range of columns are highlighted and a sort is performed on only one > column em...

MFC and XML...
Hello, Is it possible to write an MFC application using XML data in the background? If so, what is the algorithm in creating such a project? Thanks in advance, RABMissouri XML is just text so you could easily display it in an edit control. Maybe you need to provide some more information about what you're trying to do with the XML. Tom "RAB" <> wrote in message > Hello, > > Is it possible to write an MFC application using XML data in the > background? If so, what is the...

Sort not sorting all rows
I'm using Excel 2000. have created a document, uploaded it to google docs and spreadsheets, exported it as a doc, converted it to a spreadsheet (excel) and uploaded it again to google docs. It's not a complicated file - no calculations or anything, just a simple log to enable us to collaborate on change requests and website faults. New requests are assigned a number incrementally one higher than the previous. So we need to sort on the Log number column to see what the last logged number was. However, it sorts most of the spreadsheet and leaves the same 5 rows unsorted at the...

MSPersisted XML ...
I have an ADO Persisted XML file. I have a couple of XML files, 1) containes single Schemas in it and I can load this perfectly using MSPersist 2) Containes multiple Schemas and when I try to load this, ADO only sees the first schema. How do I handle an XML file with multiple schemas ? What is the best way to read this in VB.NET or C# ? Are there any examples please ? Thanks, Michael ...

Sort date by day and not year
Need to sort birthdates by month and day; ignore year. Ex: Would like to sort like list below: 3/02/1997 3/15/2002 3/21/1996 Not like this: 3/21/1996 3/02/1997 3/15/2002 Please help and thank you for your help. Kathy Hi one way: - add an additional helper column (lets ay B) - insert the following formula in B1 (if column A stores your list): =MONTH(A1) - copy this formula for all rows - sort with this helper column -- Regards Frank Kabel Frankfurt, Germany Kathy wrote: > Need to sort birthdates by month and day; ignore year. > > Ex: > Would like to sort like list below: >...

Sort and exclude certain words
Hi ... I work in a public library and frequently export lists of books from our online catalog to Excel, so that I can manipulate the data in various ways. My problem in sorting in Excel is this: Our library catalog excludes words like "The" "A" or "An" at the beginning of a title when sorting. Excel, however, does not. Is there any way I can sort on a field in Excel and have it ignore certain words at the beginning of a string? Thanks! -- jds217 ------------------------------------------------------------------------ jds217's Profile: http://www.exc...

Not sorting as expected
I have a database some 10 columns wide and 1200 rows deep. When I sort by one particular column it sorts BLANKS before text meaning that the data appears at the bottom of the database although still in alphabetical order. I have the formatting set to GENERAL for the whole column and do want the blank cells. None of the other columns do this. I am totally perplexed as I thought Excel sorted blanks nearer the end of it's priority. I have tried formatting the column to TEXT and even NUMBER also but it still makes the data appear at the bottom of the table. This doesn't make any se...

XML Question
Hi, Using Excel 2003 Pro. I've figured out how to pull an XML file from a remote web server into Excel and map the 2 fields I'm interested in (ProductID and ProductName) to cells, so the data looks like this ProductName ProductID Product 1 1234 Product 2 5678 etc...... However I want to reformat the results so I end up with this "Product 1" ** 0.05 ** "Product 2" ** 0.05 ** etc..... I need quotes around the product name, the 2 stars in co...

Newbie in XML with C# question
Hello, I am learning how to using XML documents to store data. I get this error: Access to the path "c:\inetpub\wwwroot\Info.xml" is denied. I have tried with the full path of the file, with / infront of the file. How do I get the data in too the xml document Here is the code below: using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Xml; using System.Xml.XPath; ...

sort without the sort button
Hi all. I have a table of strings that I have concatenated from several dro down lists. I now need to sort this data into a single column alphabetically and list all unique entries along with a percentage. I think I can do the listing unique entries etc. if I can just sort ou the problem I am having with sorting a column alphabetically. The problem is that I want to be able to use cell formulas to do th sorting as I want the sheet 'idiot proof'. The only user intervention want is for them to initially select the data they use from the dro down lists. I can do this using macro'...

xml generator
Hi All, I have an xml file with the structure below.I'd like to create dynamic number of xml files from this file based on <subreport> elements.each XML file contains subreport element only .for instance if there are 4 <subreport> elements ,I'd like to create 4 different xml files and I want them to be named based on <Ship_Via> child value in each <subreport> element. Is there somebody who can give me an idea? thanks for your help. ALI ====XML file==== <?xml version="1.0"?> <report> <subreport> <heading> ...