Altova Mailing List Archives


Re: [xsl] eliminating duplicates

From: "Mukul Gandhi" <gandhi.mukul@--------->
To:
Date: 5/12/2007 5:19:00 PM
Taking help from Abel's ideas, I find this solution nice:



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

 <xsl:output method="xml" indent="yes" />



 <xsl:template match="x">
   <x>
    <xsl:for-each select="edge[not(some $i in preceding-sibling::edge
satisfies deep-equal($i, .))]">
      <xsl:copy-of select="." />
    </xsl:for-each>
   </x>
 </xsl:template>

</xsl:stylesheet>



This when applied to the XML:



<x>
 <edge source="IGetter" target="CGetter" dependency="positive"/>
 <edge source="IGetter" target="CGetter" dependency="positive"/>
 <edge source="IGetter" target="CCount" dependency="positive"/>
 <edge source="ICount" target="IGetter" dependency="positive"/>
 <edge source="ICount" target="CGetter" dependency="positive"/>
 <edge source="ICount" target="ICount" dependency="positive"/>
 <edge source="ICount" target="CCount" dependency="positive"/>
 <edge source="ICount" target="CCount" dependency="positive"/>
</x>

Produces output:



<?xml version="1.0" encoding="UTF-8"?>
<x>
  <edge source="IGetter" target="CGetter" dependency="positive"/>
  <edge source="IGetter" target="CCount" dependency="positive"/>
  <edge source="ICount" target="IGetter" dependency="positive"/>
  <edge source="ICount" target="CGetter" dependency="positive"/>
  <edge source="ICount" target="ICount" dependency="positive"/>
  <edge source="ICount" target="CCount" dependency="positive"/>
</x>

On 5/11/07, Garvin Riensche <g.riensche@xxxxxxx> wrote:
Hello,



I am wondering what's the best way of getting rid of duplicate nodes
which contain more than one attribute. Suppose I have den following xml:


<edge source="IGetter" target="CGetter" dependency="positive"/>
<edge source="IGetter" target="CGetter" dependency="positive"/>
<edge source="IGetter" target="CCount" dependency="positive"/>
<edge source="ICount" target="IGetter" dependency="positive"/>
<edge source="ICount" target="CGetter" dependency="positive"/>
<edge source="ICount" target="ICount" dependency="positive"/>
<edge source="ICount" target="CCount" dependency="positive"/>
<edge source="ICount" target="CCount" dependency="positive"/>

How do I get rid of one
<edge source="IGetter" target="CGetter" dependency="positive"/>
and one
<edge source="ICount" target="CCount" dependency="positive"/>
which appear twice?

If there was only one attribute, lets say "source" it would be simple:



<xsl:for-each
select="//edge[not(./@source=preceding-sibling::edge/@source)]">
  <xsl:copy-of select="."/>
</xsl:for-each>

So I thought with more attributes this would work:
<xsl:for-each select="//edge[not(./@source=preceding-sibling::edge/@source
               and ./@target=preceding-sibling::edge/@target
               and ./@dependency=preceding-sibling::edge/@dependency
               )]">
</xsl:for-each>

But of course it doesen't because in one iterartion the
"preceding-siblings" doesn't point to the same element.

So, any help would be appreciated on how to get rid of duplicates.



Regards,
Garvin




--
Regards,
Mukul Gandhi

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.