[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Merge? Copy?

Subject: Re: Merge? Copy?
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Thu, 15 Jul 2004 21:01:05 -0700 (PDT)
xsl merge
This is a grouping problem, and can be solved using
Muenchian grouping -

<?xml version="1.0"?> 
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
 
<xsl:output method="xml" indent="yes" /> 

<xsl:key name="by-customer" match="Customer" use="@id"
/>
 
<xsl:template match="/Customers">
  <Customers>
    <xsl:for-each select="Customer[generate-id(.) =
generate-id(key('by-customer',@id)[1])]">
      <Customer id="{@id}">
        <Name>
          <xsl:value-of select="Name" />
        </Name> 
        <Address>
          <xsl:value-of select="Address" />
        </Address>
        <xsl:for-each select="key('by-customer',@id)">
          <Sales> 
	    <date>
	      <xsl:value-of select="Sales/date" />
	    </date> 
	    <amount>
	      <xsl:value-of select="Sales/amount" />
	    </amount> 
	  </Sales>
        </xsl:for-each>
      </Customer>
    </xsl:for-each>
  </Customers> 
</xsl:template>
  
</xsl:stylesheet>

Regards,
Mukul

--- sbz sbz <sbz@xxxxxxxxxxxxxxxxx> wrote:
> I have an XML file similiar to below.  In this
> example I need the Customer to appear only once, in
> the real file it may be there once or 20 times.  I
> need the Sales data do be copied up from any
> duplicate customer. 
> 
> I have thought about doing this using vbscript
> maybe, but would prefer XSL to do it.  I have looked
> at merge but that requires loading 2 xml docs in. 
> I'd also prefer not have a duplicate xml file ...
> the file will be over 600 megs so loading two would
> be intensive.   
> 
> Is this even possible? 
> Any tips would be appreciated.  Thank You. 
> 
> <Customers> 
> <Customer id="100"> 
> <Name></Name> 
> <Address></Address> 
> <Sales> 
> <date>August 1, 2004</date> 
> <amount>18</amount> 
> </Sales> 
> </Customer> 
> <Customer id="100"> 
> <Name></Name> 
> <Address></Address> 
> <Sales> 
> <date>August 10, 2004</date> 
> <amount>22</amount> 
> </Sales> 
> </Customer> 
> </Customers> 
> 
> Desired Result: 
> 
> <Customers> 
> <Customer id="100"> 
> <Name></Name> 
> <Address></Address> 
> <Sales> 
> <date>August 1, 2004</date> 
> <amount>18</amount> 
> </Sales> 
> <Sales> 
> <date>August 10, 2004</date> 
> <amount>22</amount> 
> </Sales> 
> </Customer> 
> </Customers> 



		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail 

Current Thread
  • Merge? Copy?
    • sbz sbz - Thu, 15 Jul 2004 21:33:22 -0400
      • Mukul Gandhi - Thu, 15 Jul 2004 21:01:05 -0700 (PDT) <=

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.