xsl-list
[Top] [All Lists]

Re: help on removing duplicates

2005-01-21 06:26:12
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


--~------------------------------------------------------------------
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>