Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| 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 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
  #1 (permalink)  
Old June 13th, 2005, 11:14 AM
Registered User
 
Join Date: Jun 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default translating a flat xml to a hierarchical xml

We have a "flat" xml:

<CLO>Customer</CLO>
<DIN>Date</DIN>
<ORD>Product234</ORD>
<QTY>23</QTY>
<ORD>Product676</ORD>
<QTY>25</QTY>

we need to translate this to a hierarchical view, something like:

<Header>
   <CLO>Customer</CLO>
   <DIN>Date</DIN>
   <Details>
      <Detail>
         <ORD>Product234</ORD>
         <QTY>23</QTY>
      </Detail>
      <Detail>
         <ORD>Product676</ORD>
         <QTY>25</QTY>
      </Detail>
   </Details>
</Header>

So we iterate the nodes and for each <CLO> node we hit we create a <Header> node in the resultant XML, and for each <ORD> node underneath that <CLO> we output a <Detail> for that <Header>.

One problem is we do not know how many <CLO> nodes there will be or how many <ORD> nodes refer to that <CLO> (the subsequent <ORD> nodes always apply to the previous <CLO>).

The big issue is that we need to open a <Header> node if we find a <CLO> but we wont be closing that header node until we have iterated the nodes a few more times to find the next <CLO> this causes the XSL document to not be well formed and so does not work.

Can anyone give us any tips on how to do this?

Thanks for your time

  #2 (permalink)  
Old June 13th, 2005, 11:59 AM
Authorized User
Points: 251, Level: 5
Points: 251, Level: 5 Points: 251, Level: 5 Points: 251, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Canada.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rushman
Default

Yo!

Why don't you post your XSL just see where you are now. This forum is cool but don't expect someone to work for you for free...

Let's see what's wrong with your code, and then you might get help.

Hasta pronto!
Rushman

Dijkstra's law on Programming and Inertia:

If you don't know what your program is supposed to do, don't try to write it.
  #3 (permalink)  
Old June 13th, 2005, 02:09 PM
Registered User
 
Join Date: Jun 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry Rushman, I found your reply both unhelpful and antagonistic. I am not asking anyone to work for me for free. I was was asking for tips not code.

I cannot think of a way to do what I am looking to do, in fact I actually don't think it is possible, with that in mind I have no code to show.

I am not looking for a "what is wrong with this code" answer, but rather a few helpful hints or tips on how to overcome this specific problem.

  #4 (permalink)  
Old June 13th, 2005, 05:43 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Try a search for "XSLT positional grouping".

In 2.0 use <xsl:for-each-group group-starting-with="CLO"/>.

In 1.0 it's rather more difficult.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
  #5 (permalink)  
Old June 13th, 2005, 05:55 PM
Registered User
 
Join Date: Jun 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks very much mhkay, thats exactly what I was looking for.



Similar Threads
Thread Thread Starter Forum Replies Last Post
translating XML into CSV file vxc2222 XSLT 1 December 29th, 2007 12:01 PM
Help in making a FLAT xml to a structured xml shlomi XSLT 0 July 19th, 2007 07:58 AM
tree xml to flat xml whiteadi XSLT 2 November 14th, 2006 02:36 PM
flat XML to hierarchical XML eduijs XSLT 1 April 28th, 2006 05:43 AM
Translating a XML with XSL and saving results DevOne XML 1 April 9th, 2005 07:32 AM





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