Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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....


Reply With Quote
  #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....

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:35 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.