[xsl] Removing duplicates

Subject: [xsl] Removing duplicates
From: Clay Leeds <cleeds@xxxxxxxxxx>
Date: Tue, 22 Oct 2002 09:18:59 -0700
Howdy,

I need to make certain that I don't print the same value twice on a detail line. I have up to 6 values, and I've been trying to brute force it, by making certain it's not equal to a previous item (see below). I display the RC, unless a corresponding TRC exists. BTW, the code below doesn't work (still trying to iron out the kinks). Is there a shorter way to do this? (i.e., one that actually uses XPath :-)

XML INPUT:
<RCDATA>
  <RCDATALINE>
    <RC>66</RC>
    <TRC>02</TRC>
  </RCDATALINE>
  <RCDATALINE>
    <RC>01</RC>
    <TRC>02</TRC>
  </RCDATALINE>
  <RCDATALINE>
    <RC></RC>
    <TRC></TRC>
  </RCDATALINE>
  <RCDATALINE>
    <RC></RC>
    <TRC></TRC>
  </RCDATALINE>
  <RCDATALINE>
    <RC></RC>
    <TRC></TRC>
  </RCDATALINE>
  <RCDATALINE>
    <RC></RC>
    <TRC></TRC>
  </RCDATALINE>
</RCDATA>


XSL INPUT: (BTW, I have a similar/identical template for TRC)

<xsl:for-each select="RCDATALINE">
<xsl:choose>
<xsl:when test="RCDATALINE[1]">
<xsl:apply-templates select="RC"/>
</xsl:when>
<xsl:when test="RCDATALINE[2] and RC[.!=RC[1]]">
<xsl:apply-templates select="RC"/>
</xsl:when>
<xsl:when test="RCDATALINE[3] and RC[.!=RC[1]] and RC[.!=RC[2]]">
<xsl:apply-templates select="RC"/>
</xsl:when>
<xsl:when test="RCDATALINE[4] and RC[.!=RC[1]] and RC[.!=RC[2]] and RC[.!=RC[3]]">
<xsl:apply-templates select="RC"/>
</xsl:when>
<xsl:when test="RCDATALINE[5] and RC[.!=RC[1]] and RC[.!=RC[2]] and RC[.!=RC[3]] and RC[.!=RC[4]]">
<xsl:apply-templates select="RC"/>
</xsl:when>
<xsl:when test="RCDATALINE[6] and RC[.!=RC[1]] and RC[.!=RC[2]] and RC[.!=RC[3]] and RC[.!=RC[4]] and RC[.!=RC[5]]">
<xsl:apply-templates select="RC"/>
</xsl:when>
</xsl:choose>
</xsl:for-each>



- Clay Leeds - Web Developer/Programmer - cleeds@xxxxxxxxxx


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



Current Thread