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

RE: Merging Two Files and Removing Duplicate Nodes

Subject: RE: Merging Two Files and Removing Duplicate Nodes
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Fri, 6 Jul 2001 19:06:53 +0100
how to merge two files
> I am trying to merge two files so that the output contains
> only products
> that have matching codes on both files.  In addition, I don't want the
> output to contain duplicate child elements under product
> I've been able to get matching products using the folllowing
> xsl and then
> copy the children from each file.  I just haven't figured how
> to exclude
> child nodes from the second file if they exist on the first file.
>
> <xsl:template match="/">
>     <xsl:apply-templates
> select="*//product[./code=document($second-file)//product/code]"/>
> </xsl:template>

Unless your processor is very clever, that's going to have O(m*n)
performance. I'd strongly recommend using keys, even though you can no
longer do the selection in one XPath statement:

<xsl:key name="prod2" match="second-file-list/product" use="code"/>

<xsl:template match="/">
  <xsl:for-each select="first-file-list/product">
    <xsl:variable name="code" select="code"/>
    <xsl:for-each select="document($second-file)">
      <xsl:apply-templates select="key('prod2', $code)">

This will process all the products on the second file that also exist on the
first file; products that are not present on both files will not be
processed.

Mike Kay
Software AG


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

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.