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

How to convert flat data to hierarchical data

Subject: How to convert flat data to hierarchical data
From: "Hansen, John" <John.Hansen@xxxxxxxxxx>
Date: Mon, 26 Apr 2004 10:00:11 -0700
flat data
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.