[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] help on removing duplicates


Subject: Re: [xsl] help on removing duplicates
From: "jvalentin" <jvalentin@xxxxxxxxxx>
Date: Fri, 21 Jan 2005 14:26:12 +0100 (CET)

from this xml:
<xml>
  <el>
    <node>A</node>
    <rel>
      <el><node>X</node></el>
    </rel>
  </el>
  <el>
    <node>A</node>
    <rel>
      <el><node>X</node></el>
    </rel>
  </el>
  <el>
    <node>A</node>
    <rel>
      <el><node>Y</node></el>
    </rel>
  </el>
  <el>
    <node>B</node>
    <rel>
      <el><node>X</node></el>
    </rel>
  </el>
  <el>
    <node>B</node>
    <rel>
      <el><node>Z</node></el>
    </rel>
  </el>
  <el>
    <node>B</node>
    <rel>
      <el><node>Z</node></el>
    </rel>
  </el>
  <el>
    <node>C</node>
    <rel>
      <el><node>Z</node></el>
    </rel>
  </el>
</xml>

i want to get a list -for each elect (el)- of the first level nodes (A, B,
C..) with their related nodes (X, Y, Z...) but removing duplicates, so i'd
like to get:
        A-XY
        B-XZ
        C-Z
        ...

i am using this duplicate removing xsl script:
<xsl:template match = "/">
  <!-- predicate to avoid node ABC... group repetition -->
  <xsl:apply-templates select="/xml/el[not(node=following::node)]">
    <xsl:sort select="node" />
  </xsl:apply-templates>
</xsl:template>

<xsl:template match="el">
  <xsl:value-of select="node">-<xsl:call-template
name="XXX"><xsl:with-param name="node" ><xsl:value-of select="node"
/></xsl:with-param></xsl:call-template>
</xsl:template>

<xsl:template name="XXX">
  <!--
  when using:
  <xsl:for-each
select="/xml/el[node=$node]/rel/el/node[not(text()=following::text())]">
  the first predicate is not accounted for, and all XYZ are visible and i
get this:
        A-Y
        B-X
        C-Z

  and if i use this axe:
  <xsl:for-each
select="/xml/el[node=$node]/rel/el/node[not(text()=following-sibling::text())]">
  i get again all with duplicates:
        A-XXY
        B-XZZ
        C-Z

  when i use no last predicate:
  <xsl:for-each select="/xml/el[node=$node]/rel/el/node">
  intra-class ABC duplicates remain:
        A-XXY
        B-XZZ
        C-Z
  -->
    <xsl:value-of select="text()">
  </xsl:for-each>
</xsl:template>

any idea on what's the reason for this behaviour of predicate [node=$node]
(i tried keys with the same result)

thanks

> Hi Juan,
>
>>as i don't have tight performance problems i don't need to resort to
>>muenchian methods, any idea on how to solve this ?
>
> But with keys, you consider only the first member in a key list.
> Duplicates removed.
>
> Cheers,
>
> Juergen


Current Thread
Keywords
xsl