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

Removing Duplicate Nodes

Subject: Removing Duplicate Nodes
From: "agiuswiltonites@xxxxxxxx" <agiuswiltonites@xxxxxxxx>
Date: Sun, 18 Mar 2012 07:09:14 GMT
 Removing Duplicate Nodes
II am using XSLT 1.0 in an asp environment. I searched the faq and archives
and have not found an example I can go by. I am trying to figure out how to
remove duplicate <loc>. If <loc> is a duplicate then remove the containing
<url> and all its contents. I have my xslt somewhat working. It removes the
<loc> if it is a duplicate, but leaves the leftover <lastmod>, <priority>, and
<changefreq> for each duplicate. Any help would be greatly appreciated. Jake

Here is my XSLT Code:

<?startSampleFile ?>
<!-- xq495.xsl: converts xq494.xml into xq496.xml -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:s="http://www.sitemaps.org/schemas/sitemap/0.9"
exclude-result-prefixes="s">

<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:key name="kloc" match="s:loc"
use="." />
<xsl:key name="klastmod" match="s:lastmod"
use="../s:loc"/>
<xsl:key name="kpriority" match="s:priority"
use="../s:loc"/>
<xsl:key name="kchangefreq" match="s:changefreq"
use="../s:loc"/>

<xsl:template match="/*">

<xsl:for-each select=
"*/s:loc[generate-id()
=
generate-id(key('kloc',.)[1])]">
<xsl:value-of select="."/>
<xsl:for-each select="key('klastmod', .)">
<xsl:value-of select="."/>
</xsl:for-each>
<xsl:for-each select="key('kpriority', .)">
<xsl:value-of select="."/>
</xsl:for-each>
<xsl:for-each select="key('kchangefreq', .)">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

Existing XML:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://www.example.com/first</loc>
<lastmod>2012-01-27T10:18:26+00:00</lastmod>
<priority>0.90</priority>
<changefreq>daily</changefreq>
</url>
<url>
<loc>http://www.example.com/second</loc>
<lastmod>2012-03-16T07:38:42+00:00</lastmod>
<priority>0.60</priority>
<changefreq>weekly</changefreq>
</url>
<url>
<loc>http://www.example.com/second</loc>
<lastmod>2012-03-16T08:36:44+00:00</lastmod>
<priority>0.60</priority>
<changefreq>weekly</changefreq>
</url>
<url>
<loc>http://www.example.com/third</loc>
<lastmod>2012-03-16T08:37:09+00:00</lastmod>
<priority>0.60</priority>
<changefreq>weekly</changefreq>
</url>
</urlset>

Desired Output:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://www.example.com/first</loc>
<lastmod>2012-01-27T10:18:26+00:00</lastmod>
<priority>0.90</priority>
<changefreq>daily</changefreq>
</url>
<url>
<loc>http://www.example.com/second</loc>
<lastmod>2012-03-16T07:38:42+00:00</lastmod>
<priority>0.60</priority>
<changefreq>weekly</changefreq>
</url>
<loc>http://www.example.com/third</loc>
<lastmod>2012-03-16T08:37:09+00:00</lastmod>
<priority>0.60</priority>
<changefreq>weekly</changefreq>
</url>
</urlset>

____________________________________________________________
3 Free Credit Scores
Equifax&#174;: Help Guard Your Identity. Sign up for a 30 Day Free Trial!
http://thirdpartyoffers.juno.com/TGL3131/4f658a7e411d721ec39est03vuc

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.