Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
| FAQ | Members List | 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
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 9th, 2007, 08:13 AM
Registered User
Join Date: Jul 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default merging xml using xslt


I'm trying to merge several xml files into one master file but is sofar without success. All help is appreciated.

The scenario is as follows

All source xml files have two sets of data: clients and items
each client is identified using the client name and a numeric id which is referenced from the items. One file can look like this:

  <name>client A</name>
  <name>client C</name>
  <name>client F</name>
  <name>item 100</name>
  <name>item 100</name>
  <name>item 200</name>
  <name>item 200</name>

This structure is repeated in all source xml files, in each source file the client is defined and only referenced from the items but different source xml files may have the same client defined using a different id, so in order to merge the clients I have to make a global client list containing all clients by name and issue new id values where the id is used by a different client (does this make sense??)
The Item id should be unique no matter which source xml file are used, but also here there might be identical items, but for now assume that these are unique.

The case is: merge several xml files with identical structure into one xml (still with the same structure) but sort clients based on client name and items based on item id.

Please help

Reply With Quote
  #2 (permalink)  
Old July 9th, 2007, 06:07 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

Looks like a multi-pass problem to me: break the problem down into a number of smaller problems.

There's an element of grouping here and grouping problems, especially cross-document grouping problems, are always easier with XSLT 2.0.

Phase 1 is probably to build your consolidated client file, which can be done something like:

<xsl:for-each-group select="collection(....)/x/client" group-by="name">
    <id><xsl:value-of select="position()"/></id>
    <name><xsl:value-of select="current-grouping-key"/></name>

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
merging 2 xml with xslt gbordel XSLT 7 April 24th, 2008 05:27 AM
Merging XML Help Please sam666 XML 7 March 8th, 2006 02:50 AM
merging a node from one XML to another pravind XSLT 3 February 21st, 2006 05:04 AM
Merging 2 Xml docs nkuar XML 3 December 8th, 2005 05:22 AM
merging 2 xml documents espider4u XSLT 0 August 31st, 2004 11:48 AM

All times are GMT -4. The time now is 09:51 PM.

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