Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 29th, 2007, 09:39 AM
Registered User
 
Join Date: Jan 2007
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

 
Old January 29th, 2007, 10:25 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Flat structure to Nested dani1 XSLT 2 October 29th, 2008 02:51 AM
Flat XML structure to a tree by XSLT Borg0011 XSLT 2 July 9th, 2006 08: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 03:36 PM
mapping repeating xml structure to flat csv f vasmallela Biztalk 0 May 29th, 2005 11:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.