[xsl] How to remove double elements?????

Subject: [xsl] How to remove double elements?????
From: ChivaBaba@xxxxxxx
Date: Thu, 16 May 2002 12:16:02 EDT
Hi,

I have some pretty fussy code to copy some elements from an xml-file, sort them amd eliminate double elements:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++

<!-- get for each computer in sw-file the corresponding computer in hw-file-->   
 
 <xsl:variable name="computer">
  <xsl:for-each select="tool">
      
<!--.... build the key of the current tool .........-->

   <xsl:variable name="key" select="concat(@name,'#',@version)"/>

<!-........ change context for key lookup ..........-->
      
   <xsl:for-each select="$sw-file">  
    <xsl:variable name="release" select="key('releasekey',$key)"/>     
    <xsl:for-each select="$release/computer">
     <xsl:variable name="name_key" select="@name"/>

<!--.......... change context for key lookup .......-->
      
     <xsl:for-each select="$hw-file">
      <xsl:copy-of select="key('hw_key',$name_key)"/>  
     </xsl:for-each>
    </xsl:for-each>
   </xsl:for-each>
  </xsl:for-each>
 </xsl:variable>

<!--.............. get sorted computer-list .......-->
 
 <xsl:variable name="sorted_hw">
  <xsl:for-each select="exsl:node-set($computer)/computer">
   <xsl:sort data-type="text" lang="en" select="@function"/>
   <xsl:sort data-type="text" lang="en" select="@name"/>
   <xsl:copy-of select="."/>
  </xsl:for-each>
 </xsl:variable>

<!--........... remove double elements .............-->

 <xsl:variable name="hw">
  <xsl:for-each select="exsl:node-set($sorted_hw)/computer">
   <xsl:if test="preceding-sibling::computer[1]/@name != @name">
    <xsl:copy-of select="."/>
   </xsl:if>
  </xsl:for-each>
 </xsl:variable>

++++++++++++++++++++++++++++++++++++++++++++++++++++++++

1.)
Is there an elegant possibility to remove double elements??? By using my version the first element gets lost!!

2.) 
Is it possible to get these functionaltities with LESS code (especially with LESS variables)??????

Many thanks in advance!!!

Cheers,

Stefan

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


Current Thread