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 March 28th, 2007, 02:10 PM
Registered User
 
Join Date: Aug 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can I use XSLT to "unflatten" a list?

I've been handed some XML that's basically flat:

<foo>
 <bar att="1"/>
 <bar att="2"/>
 <bar att="3"/>
 <bar att="3"/>
 <bar att="2"/>
 <bar att="3"/>
 <bar att="3"/>
 <bar att="2"/>
</foo>

and so on. Is there a good trick for "unflattening" this list, based on the attribute, so that I can end up with something like this:

  <One>
   <Two>
    <Three/>
    <Three/>
   </Two>
   <Two>
    <Three/>
    <Three/>
   </Two>
   <Two/>
  </One>

That attribute is consistent enough for me to use it as my guideline. I can find those. But since it's not really nested, once I find one, I'm not really sure to say "Now that I've landed on this 2, start looking at the 3s under it and stop when you get to another 2."
At each level I don't know how many children I will have, either.




 
Old March 28th, 2007, 03:04 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

For an XSLT 2.0 solution to this, see

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

It can be done in 1.0, but it's much harder.

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
General XSLT Questions in the XSLT Forum jminatel BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 0 March 31st, 2008 07:50 PM
Can XSLT read DTD/schema and Generate XSLT.. ROCXY XSLT 1 November 6th, 2006 09:39 AM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM
fill dropdown list with items when parent list isaac_cm Pro PHP 1 July 10th, 2006 05:41 AM
List tablesname from database & list databasename ittorget MySQL 3 September 10th, 2005 03:06 AM





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