Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 29th, 2007, 09:39 AM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Flat DB structure into XML Hierarchy

Hi there, pretty new to XSLT and wondered if anyone could point me in the right direction. I'm trying to take a flat db structure from a query and transform it into a hierarchical xml structure.

This is the flat structure from the db:

<data>
   <row>
      <section_depth>1</section_depth>
      <section_title>Home</section_title>
   </row>
   <row>
      <section_depth>2</section_depth>
      <section_title>Events</section_title>
   </row>
   <row>
      <section_depth>3</section_depth>
      <section_title>Event 1</section_title>
   </row>
   <row>
      <section_depth>3</section_depth>
      <section_title>Event 2</section_title>
   </row>
   <row>
      <section_depth>2</section_depth>
      <section_title>Equipment</section_title>
   </row>
   <row>
      <section_depth>2</section_depth>
      <section_title>News</section_title>
   </row>
   <row>
      <section_depth>3</section_depth>
      <section_title>News 1</section_title>
   </row>
   <row>
      <section_depth>3</section_depth>
      <section_title>News 2</section_title>
   </row>
</data>

I'm looking to transform this with XSLT 2, into this using the section_depth as the indentation, can always assume the flat structure will be in the right order:

<site>
   <section>
      <title>Home</title>
      <section>
         <title>Events</title>
         <section>
            <title>Event 1</title>
         </section>
         <section>
            <title>Event 2</title>
         </section>
      </section>
      <section>
         <title>Equipment</title>
      </section>
      <section>
         <title>News</title>
         <section>
            <title>News 1</title>
         </section>
         <section>
            <title>News 2</title>
         </section>
      </section>
   </section>

I've played around with grouping but my head started to hurt. Thanks in advance for any help!

Dave

Reply With Quote
  #2 (permalink)  
Old January 29th, 2007, 10:25 AM
mhkay's Avatar
Wrox Author
Points: 18,420, Level: 59
Points: 18,420, Level: 59 Points: 18,420, Level: 59 Points: 18,420, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,952
Thanks: 0
Thanked 289 Times in 284 Posts
Default

There's a paper that solves essentially this problem at

http://www.idealliance.org/proceedin...mhk-paper.html

Your head will probably still hurt for a while, but the solution is surprisingly simple.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Flat structure to Nested dani1 XSLT 2 October 29th, 2008 03:51 AM
Flat XML structure to a tree by XSLT Borg0011 XSLT 2 July 9th, 2006 09:58 AM
XML parsing, hierarchy?! saebe Beginning VB 6 0 February 27th, 2006 12:17 PM
flat to hierarchy wu4 XSLT 3 October 19th, 2005 04:36 PM
mapping repeating xml structure to flat csv f vasmallela Biztalk 0 May 30th, 2005 12:53 AM



All times are GMT -4. The time now is 10:14 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.