473,388 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

'Sort' One XML file into another XML file? (Help required pls!)

In need of some good advice on 'consolidating' an XML file into another folks. Hope you can help!

My souce XML looks like so:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <vehicles>
  3.     <make xmake="ALFA ROMEO">
  4.         <model xmodel="159 SPORTWAGON">
  5.             <derivative xderivative="3.2 V6 JTS Q4 Lusso 5dr" />
  6.         </model>
  7.     </make>
  8.     <make xmake="ALFA ROMEO">
  9.         <model xmodel="SPIDER CONVERTIBLE">
  10.             <derivative xderivative="3.2 V6 JTS Q4 2dr" />
  11.         </model>
  12.     </make>
  13.     <make xmake="ALFA ROMEO">
  14.         <model xmodel="SPIDER CONVERTIBLE">
  15.             <derivative xderivative="2.8 V6 Q4 2dr" />
  16.         </model>
  17.     </make>
  18.     <make xmake="CITROEN">
  19.         <model xmodel="C4 COUPE SPECIAL EDITIONS">
  20.             <derivative xderivative="1.6HDi 16V by LOEB 3dr" />
  21.         </model>
  22.     </make>
  23.     <make xmake="FORD">
  24.         <model xmodel="S-MAX DIESEL ESTATE">
  25.             <derivative xderivative="2.0 TDCi LX 5dr" />
  26.         </model>
  27.     </make>
  28. </vehicles>
  29.  
Basically I have several vehicles but need to group them by Make, Model and Derivative thus:
Expand|Select|Wrap|Line Numbers
  1. <vehicles>
  2.                 <make name='ALFA ROMEO'>
  3.                                 <model name='159 SPORTWAGON'>
  4.                                 <Derivative>3.2 V6 JTS Q4 Lusso 5dr</Derivative>
  5.                                 </model>
  6.                                 <model name='SPIDER CONVERTIBLE'>
  7.                                                 <Derivative>3.2 V6 JTS Q4 2dr</Derivative>
  8.                                                 <Derivative>2.8 V6 Q4 2dr</Derivative>
  9.                                 </model>
  10.                 </make>
  11.  
  12.                 <make name='CITROEN'>
  13.                                 <model name='C4 COUPE SPECIAL EDITIONS'>
  14.                                                 <Derivative>1.6HDi 16V by LOEB 3dr</Derivative>
  15.                                 </model>
  16.                 </make>
  17.  
  18.                 <make name='FORD'>
  19.                                 <model name='S-MAX DIESEL ESTATE'>
  20.                                                 <Derivative>2.0 TDCi LX 5dr</Derivative>
  21.                                 </model>
  22.                 </make>
  23. </vehicles>
  24.  
I'm pretty new to using XSL so any pointers towards how to acheive this would be gratefully received!

Many thanks!
TM2AM
Jan 22 '09 #1
1 1895
jkmyoung
2,057 Expert 2GB
It's multi-level Muenchian Grouping:
Jeni's XSLT Pages: Grouping Using the Muenchian Method
Expand|Select|Wrap|Line Numbers
  1. <xsl:key name="vehicle-by-make" match="make" use="@xmake"/>
  2. <xsl:key name="vehicle-by-make-model" match="make" use="concat(@make, '_', model/@xmodel)"/>
  3. ...
  4. ...
  5. <xsl:for-each select="make[count(.|key('vehicle-by-make', @xmake)[1]) = 1]">
  6. <xsl:copy>
  7. ....
  8. <xsl:for-each select="key('vehicle-by-make', @xmake)[count(.|key('vehicle-by-make-model', concat(@make, '_', model/@xmodel)[1]) = 1]">
  9. ...
  10. <xsl:for-each select=key('vehicle-by-make-model', concat(@make, '_', model/@xmodel)">
  11.  
  12.  
It's the 2nd for-each which is the most confusing.
Jan 23 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Cherrish Vaidiyan | last post by:
hello, Thanx for replying to my earlier Google group query about Replication of Oracle 9i on RH9.IF the query followed is being repeated by me I am sorry for it.. I want to implement...
1
by: stuart dent via .NET 247 | last post by:
XML validation error. Help required If anyone can help me, thankyou, thankyou... When I run this code code I get this error: The data at the root level is invalid. Line 1, position 39. I...
1
by: DjordjeD | last post by:
I need to call(reference) class member "PrintDestination.PrintDestinationPrinter" from another file. How do I do it, I tried "ReportRenderer.PrintDestination.PrintDestinationPrinter" but it...
19
by: **Developer** | last post by:
When I get the image from the file the file remains locked so the Delete fails with a "used by another process" So I tried using a clone and disposing the obtained image. But that didn't fix...
4
by: MLH | last post by:
Setting form's Picture property to another file from within VBA doesn't repaint the form with new bitmap - for instance... Me.Picture = "c:\pics\MyNewPic.jpg" I tried Me.Repaint afterward,...
5
by: Peter Olcott | last post by:
I have used the standard template library quite a bit, and std::sort has been very useful. Now I have reached the point where my memory requirements are exceeded. Is there some standard way to sort...
0
by: sandesh964 | last post by:
i am developing an online application iv written the code using c# with asp now my code is not working when my listbox contains even number of items in it can any one help me pls here goes the code...
1
by: nth | last post by:
I wan to filter the database show out information by using the user login name. Means that when that user login by entering their names n password, if correct then it will go to the other page by...
2
by: fusionfusion | last post by:
Hi I want to avoid hardcoding the filepath in my C program. I want to store the filepath in a variable in a text file. then i have to pass that variable to another file. ex....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.