|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Merging Two Files and Removing Duplicate Nodes
> 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








