xsl-list
[Top] [All Lists]

RE: [xsl] eliminating duplicates

2007-05-10 13:57:45
I had to wrap your edge elements in a root element to do this.

This is a special case solution. It will fail, for instance, in the case where 
two consecutive edge nodes have values for @source, @target, and @dependency 
that while compared individually are different, but when concatenated are the 
same.

Nonetheless, this may serve your need.

  <xsl:variable name="sorted-list">
    <xsl:for-each select="//edge">
      <xsl:sort select="@source" />
      <xsl:sort select="@target" />
      <xsl:sort select="@dependency" />
      <xsl:copy-of select="." />
    </xsl:for-each>
  </xsl:variable>


    <xsl:template match="/list">
      <list>
        <xsl:apply-templates select="$sorted-list/edge" />
      </list>
    </xsl:template>

<xsl:template match="edge[not(concat(@source, @target, @dependency) = 
concat(preceding-sibling::edge[1]/@source, preceding-sibling::edge[1]/@target, 
preceding-sibling::edge[1]/@dependency))]">
  <xsl:copy-of select="." />
</xsl:template>
-- 
Charles Knell
cknell(_at_)onebox(_dot_)com - email



-----Original Message-----
From:     Garvin Riensche <g(_dot_)riensche(_at_)gmx(_dot_)net>
Sent:     Thu, 10 May 2007 22:05:10 +0200
To:       xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject:  [xsl] eliminating duplicates

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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>