[xsl] Correct syntax for removing duplicates from sorted list

Subject: [xsl] Correct syntax for removing duplicates from sorted list
From: "Ahmad J Reeves" <ahmad@xxxxxxxxxxxxxx>
Date: Mon, 17 Dec 2001 12:59:48 -0000
Hi,

I am trying to remove duplicate copies of context nodes from a sorted
list. My xml doc looks like this:-

<LOG>
      <DIRECT>
      <COMMUNICATION_TYPE> PAGETELL </COMMUNICATION_TYPE>
      <Invoc_serial> 27 </Invoc_serial>
      <Serial> 3087908 </Serial>
      <USAGE> TELL </USAGE>
      <MESSAGE_TYPE> EMOTE </MESSAGE_TYPE>
      <CHARACTER_ID> 44639 </CHARACTER_ID>
      <CHARACTER_STATUS> 3 </CHARACTER_STATUS>
      <LOCATION_ID> 45040 </LOCATION_ID>
      <TARGET_CHARACTER_ID> 2346456 </TARGET_CHARACTER_ID>
      <TARGET_CHARACTER_STATUS> 6 </TARGET_CHARACTER_STATUS>
      <TARGET_CHARACTER_LOCATION_ID> 23222
</TARGET_CHARACTER_LOCATION_ID>
      <MESSAGE>hello</MESSAGE>
      <TIME> 'Mon, 26 Nov 2001 15:40:29 +0000' </TIME>
      </DIRECT>

 *then a few hundred more like that*

</LOG>

My xml stylesheet as is looks like this:-


<xsl:stylesheet
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
        version="1.0">
 <xsl:output method="html"/>

 <xsl:variable name="last">
 </xsl:variable>

 <xsl:template match ="/">
 <xsl:for-each select="LOG/DIRECT/TARGET_CHARACTER_ID">
 <xsl:variable name="last" select="LOG/DIRECT/TARGET_CHARACTER_ID"/>
 <xsl:sort select="." data-type="number"/>
 <xsl:value-of select="position()"/>
 <xsl:text>. </xsl:text>

  <html>
    <body>
     <xsl:if test=not".=last">
          <xsl:value-of select="."/><br></br>
        </xsl:if>
    </body>
  </html>
  </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>

And my sorted but duplicated output is something like this:-

1. 23220
2. 23470
3. 23470
4. 23470
5. 23470
6. 23470
7. 23470
8. 83470
9. 212120
10. 223232
11. 231212
12. 2346456
13. 27675340

So every time I get to the context node(in this case "TARGET_CHARACTER_ID")
I need to check if it matches the previous one and if so NOT to output it.
This
should give me a unique list rather than a total occurences count.
The code as is (oops!) just tests to see if it equals itself I think! and
I've been looking
at axis but as I am comparing .=. then I'm not sure the best way to proceed,
as I
need to test with the previous 'iteration' as it were.

Any help gratefully received!

Cheers

Ahmad (p.s cheers Jen and Chris for your previous help)


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread