Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 8th, 2005, 01:38 PM
Authorized User
 
Join Date: Oct 2005
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Duplicates in XSLT

Hi
    I am using the following code to remove the duplicates and also to count the number of duplicates...

<xsl:variable name="string" select="'Hello, Hello,
Hello, test, dog, cat, cat'" />

<xsl:template match="/">
   <xsl:choose>
     <xsl:when test="not(contains($string, ','))">
       <xsl:value-of select="$string" />
     </xsl:when>
     <xsl:otherwise>
       <xsl:call-template name="remove-duplicates">
         <xsl:with-param name="string" select="translate($string, ' ', '')" />
         <xsl:with-param name="newstring" select="''" />
         <xsl:with-param name="count" select="1" />

       </xsl:call-template>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

<xsl:template name="remove-duplicates">
   <xsl:param name="string" />
   <xsl:param name="newstring" />
   <xsl:param name="count" />

   <xsl:choose>
     <xsl:when test="$string = ''">
       <xsl:value-of select="$newstring" />
     </xsl:when>
     <xsl:otherwise>
       <xsl:if test="contains($newstring,substring-before($string, ','))">
         <xsl:call-template name="remove-duplicates">
           <xsl:with-param name="string" select="substring-after($string, ',')" />
           <xsl:with-param name="newstring" select="$newstring" />
           <xsl:with-param name="count" select="1+$count" />
         </xsl:call-template>
       </xsl:if>
       <xsl:if test="not(contains($newstring, substring-before($string, ',')))">
         <xsl:variable name="temp">
           <xsl:if test="$newstring = ''">
             <xsl:value-of select="substring-before($string, ',')" />
             <xsl:text>-</xsl:text>
             <xsl:value-of select="$count" />
           </xsl:if>
           <xsl:if test="not($newstring = '')">
         <xsl:value-of select="concat($newstring, ',', substring-before($string, ','))" />
             <xsl:text>-</xsl:text>
             <xsl:value-of select="$count" />
           </xsl:if>
         </xsl:variable>
         <xsl:call-template name="remove-duplicates">
           <xsl:with-param name="string" select="substring-after($string, ',')" />
           <xsl:with-param name="newstring" select="$temp" />
           <xsl:with-param name="count" select="1" />
         </xsl:call-template>
       </xsl:if>
     </xsl:otherwise>
   </xsl:choose>

</xsl:template>



I am getting the following Output

Hello-1, test-3, dog-1, cat-1

But my desired output is

Hello-3, test-1, dog-1, cat-2

Can anybody help me to achieve this....


  #2 (permalink)  
Old November 9th, 2005, 11:45 AM
Authorized User
 
Join Date: Oct 2005
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi
   I have found where the actual problem is and got it fixed....



Similar Threads
Thread Thread Starter Forum Replies Last Post
Yes to duplicates MMJiggy62 Beginning VB 6 3 July 14th, 2006 11:51 AM
eliminating all but 1 of duplicates nlicata SQL Server 2000 3 November 21st, 2003 04:52 PM
Deleting duplicates prabodh_mishra SQL Server 2000 3 September 23rd, 2003 09:04 AM
Deleting Duplicates ioates SQL Server 2000 5 August 31st, 2003 10:18 AM
Duplicates ashley_y Access 11 August 14th, 2003 03:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.