[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: duplicate occurances within strings

Subject: Re: duplicate occurances within strings
From: Christopher Hansen <chansen1@xxxxxxxxx>
Date: Thu, 16 Dec 2004 22:14:48 -0500
christopher hansen
Jay, 
Wow.  Lots of code there.  Thank you though...just wish there were an
easier way to accomplish the task!

Thanks
Chris


On Thu, 16 Dec 2004 15:51:25 -0600, JBryant@xxxxxxxxx <JBryant@xxxxxxxxx> wrote:
> We had a very similar question last week, except that that person was
> getting the string from a node in the document and didn't care about a
> string-compare function. Assuming you also don't care about a
> string-compare function, here's a modification of last week's answer that
> does the job with a recursive template. If you really do want to use a
> string-compare function, someone else will have to answer your question,
> as I don't use MSXSL.
> 
> Note that my solution is case-sensitive, so Hello, hello, cat and Cat are
> all different words.
> 
> Jay Bryant
> Bryant Communication Services
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet
>   version="1.0"
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> >
> <xsl:output
>   method="text"
>   omit-xml-declaration="yes"
>   indent="no"
> />
> 
>   <xsl:template match="/">
>     <xsl:variable name="theString" select="Hello, Hello, Hello, test, dog,
> cat, cat"/>
>     <xsl:call-template name="makeList">
>       <xsl:with-param name="textIn" select="translate($theString, ',',
> '')"/>
>       <xsl:with-param name="wordsSoFar"/>
>     </xsl:call-template>
>   </xsl:template>
> 
>   <xsl:template name="makeList">
>     <xsl:param name="textIn"/>
>     <xsl:param name="wordsSoFar"/>
>     <xsl:choose>
>       <xsl:when test="contains($textIn, ' ')">
>         <xsl:variable name="firstWord" select="substring-before($textIn, '
> ')"/>
>         <xsl:choose>
>           <xsl:when test="not(contains($wordsSoFar, $firstWord))">
>             <xsl:variable name="newString">
>               <xsl:choose>
>                 <xsl:when test="string-length($wordsSoFar)=0">
>                   <xsl:value-of select="$firstWord"/>
>                 </xsl:when>
>                 <xsl:otherwise>
>                   <xsl:value-of select="$wordsSoFar"/><xsl:text>,
> </xsl:text><xsl:value-of select="$firstWord"/>
>                 </xsl:otherwise>
>               </xsl:choose>
>             </xsl:variable>
>             <xsl:call-template name="makeList">
>               <xsl:with-param name="textIn"
> select="substring-after($textIn, ' ')"/>
>               <xsl:with-param name="wordsSoFar" select="$newString"/>
>             </xsl:call-template>
>           </xsl:when>
>           <xsl:otherwise>
>             <xsl:call-template name="makeList">
>               <xsl:with-param name="textIn"
> select="substring-after($textIn, ' ')"/>
>               <xsl:with-param name="wordsSoFar" select="$wordsSoFar"/>
>             </xsl:call-template>
>           </xsl:otherwise>
>         </xsl:choose>
>       </xsl:when>
>       <xsl:otherwise>
>         <xsl:choose>
>           <xsl:when test="string-length($wordsSoFar)=0">
>             <xsl:value-of select="$textIn"/>
>           </xsl:when>
>           <xsl:otherwise>
>             <xsl:choose>
>               <xsl:when test="contains($wordsSoFar, $textIn)">
>                 <xsl:value-of select="$wordsSoFar"/>
>               </xsl:when>
>               <xsl:otherwise>
>                 <xsl:value-of select="$wordsSoFar"/><xsl:text>,
> </xsl:text><xsl:value-of select="$textIn"/>
>               </xsl:otherwise>
>             </xsl:choose>
>           </xsl:otherwise>
>         </xsl:choose>
>       </xsl:otherwise>
>     </xsl:choose>
>   </xsl:template>
> 
> </xsl:stylesheet>
> 
> Christopher Hansen <chansen1@xxxxxxxxx>
> 12/16/2004 02:59 PM
> Please respond to
> xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> 
> To
> xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> cc
> 
> Subject
>  duplicate occurances within strings
> 
> 
> If i have a variable $thestring   containing the following string:
> "Hello, Hello, Hello, test, dog, cat, cat"
> 
> Is there a way to use the string-compare function to parse it and
> check for duplicates within the string, and then possibly remove those
> extra occurrances...resulting in the string "Hello, test, dog, cat"
> 
> Thanks
> Chris

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.