Subject: [xsl] How to convert flat data to hierarchical data From: "Hansen, John" <John.Hansen@xxxxxxxxxx> Date: Mon, 26 Apr 2004 10:00:11 -0700 |
Is there a simple stylesheet that will transform the flat data shown below into the hierarchical form that is at the end of this email? I hate to ask for your help but I'm stumped at the moment. EmployeeGroup elements, while presented in a flat form in the initial XML output need to be nested based on their EmployeeGroupTree child element's SK attribute and their Parent child element's SK attribute (or xsi:nil attribute). Each level in the hierarchy can have zero or more child EmployeeGroup elements. The root of each tree is the EmployeeGroup with a <Parent xsi:nil="true"/> child. <!-- Original XML with flat structure --> <EmployeeGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <EmployeeGroup SK="1"> <EmployeeGroupTree SK="1"/> <Code>AB_GP1</Code> <Parent xsi:nil="true"/> </EmployeeGroup> <EmployeeGroup SK="2"> <EmployeeGroupTree SK="2"/> <Code>AB_GP2</Code> <Parent xsi:nil="true"/> </EmployeeGroup> <EmployeeGroup SK="3"> <EmployeeGroupTree SK="1"/> <Code>AB1_G1</Code> <Parent SK="1"/> </EmployeeGroup> <EmployeeGroup SK="4"> <EmployeeGroupTree SK="2"/> <Code>AB2_G1</Code> <Parent SK="2"/> </EmployeeGroup> <EmployeeGroup SK="5"> <EmployeeGroupTree SK="3"/> <Code>CATGRY</Code> <Parent xsi:nil="true"/> </EmployeeGroup> <EmployeeGroup SK="6"> <EmployeeGroupTree SK="4"/> <Code>CSV </Code> <Parent xsi:nil="true"/> </EmployeeGroup> <EmployeeGroup SK="7"> <EmployeeGroupTree SK="5"/> <Code>HEAP </Code> <Parent xsi:nil="true"/> </EmployeeGroup> <EmployeeGroup SK="8"> <EmployeeGroupTree SK="5"/> <Code>H1 </Code> <Parent SK="7"/> </EmployeeGroup> <EmployeeGroup SK="9"> <EmployeeGroupTree SK="5"/> <Code>H10 </Code> <Parent SK="7"/> </EmployeeGroup> <EmployeeGroup SK="10"> <EmployeeGroupTree SK="5"/> <Code>H11 </Code> <Parent SK="7"/> </EmployeeGroup> <EmployeeGroup SK="11"> <EmployeeGroupTree SK="5"/> <Code>H12 </Code> <Parent SK="7"/> </EmployeeGroup> <EmployeeGroup SK="12"> <EmployeeGroupTree SK="5"/> <Code>H13 </Code> <Parent SK="7"/> </EmployeeGroup> <EmployeeGroup SK="13"> <EmployeeGroupTree SK="1"/> <Code>TEST </Code> <Parent SK="3"/> </EmployeeGroup> <EmployeeGroup SK="14"> <EmployeeGroupTree SK="1"/> <Code>TEST2 </Code> <Parent SK="13"/> </EmployeeGroup> </EmployeeGroups> <!-- desired hierarchical output of XSL transformation --> <EmployeeGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <EmployeeGroup SK="1"> <EmployeeGroupTree SK="1"/> <Code>AB_GP1</Code> <EmployeeGroup SK="3"> <EmployeeGroupTree SK="1"/> <Code>AB1_G1</Code> <EmployeeGroup SK="13"> <EmployeeGroupTree SK="1"/> <Code>TEST </Code> <EmployeeGroup SK="14"> <EmployeeGroupTree SK="1"/> <Code>TEST2 </Code> </EmployeeGroup> </EmployeeGroup> </EmployeeGroup> </EmployeeGroup> <EmployeeGroup SK="2"> <EmployeeGroupTree SK="2"/> <Code>AB_GP2</Code> <EmployeeGroup SK="4"> <EmployeeGroupTree SK="2"/> <Code>AB2_G1</Code> </EmployeeGroup> </EmployeeGroup> <EmployeeGroup SK="5"> <EmployeeGroupTree SK="3"/> <Code>CATGRY</Code> </EmployeeGroup> <EmployeeGroup SK="6"> <EmployeeGroupTree SK="4"/> <Code>CSV </Code> </EmployeeGroup> <EmployeeGroup SK="7"> <EmployeeGroupTree SK="5"/> <Code>HEAP </Code> <EmployeeGroup SK="8"> <EmployeeGroupTree SK="5"/> <Code>H1 </Code> </EmployeeGroup> <EmployeeGroup SK="9"> <EmployeeGroupTree SK="5"/> <Code>H10 </Code> </EmployeeGroup> <EmployeeGroup SK="10"> <EmployeeGroupTree SK="5"/> <Code>H11 </Code> </EmployeeGroup> <EmployeeGroup SK="11"> <EmployeeGroupTree SK="5"/> <Code>H12 </Code> </EmployeeGroup> <EmployeeGroup SK="12"> <EmployeeGroupTree SK="5"/> <Code>H13 </Code> </EmployeeGroup> </EmployeeGroup> </EmployeeGroups>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] html: datetime e bit type, Jarno.Elovirta | Thread | RE: [xsl] How to convert flat data , Andreas L. Delmelle |
Re: [xsl] Sorting in Ancient Greek, Eliot Kimber | Date | RE: [xsl] How to convert flat data , Andreas L. Delmelle |
Month |