Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Sort XML Into Hierarchy

From: "e" <e2d@--.--->
To: NULL
Date: 8/6/2006 9:18:00 AM

it looks like grouping more than sorting to me, it is the case then grouping 
in not easy using XSLT but posible, take a look at Muenchian group algorithm
http://www.jenitennison.com/xslt/grouping/muenchian.html

cheers
erymuzuan
www.bespoke.com.my

"csharp" <jasoncalton@h...> wrote in message 
news:1154698953.724257.182690@s......
>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.BaseDirectory +
> "xsl.xsl");
> xsltransform.Transform(System.AppDomain.CurrentDomain.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)
> 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent