This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: replace function


That happens to be the same as the example I had referred you to earlier.

>You can use a replace template. Chuck White has an example on page 594 of
his book Mastering XSLT

Sorry if you thought I was being derogatory, I am a newbie too. Next time I
won't be so lazy and will type out the solution... 


-----Original Message-----
From: Stevenson Ngila [mailto:Stevenson@epr.footman-walker.com]
Sent: Tuesday, October 01, 2002 3:00 AM
To: xsl-list@lists.mulberrytech.com
Subject: RE: [xsl] replace function


Thanks Michael Kay, i wrote one and it worked perfectly. See it below:

<xsl:template name="stringSpacing">
  <xsl:param name="sString"/>
  <xsl:choose>
    <xsl:when test="contains($sString, ',')">
	<xsl:value-of select="substring-before($sString, ',')"/>,&#32;

	<xsl:call-template name="stringSpacing">
	        <xsl:with-param name="sString"
select="substring-after($sString,
',')" />
	 </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
        <xsl:value-of select="$sString"/>
  </xsl:otherwise>
  </xsl:choose>
</xsl:template>

-----Original Message-----
From: owner-xsl-list@lists.mulberrytech.com
[mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of Michael Kay
Sent: 30 September 2002 23:06
To: xsl-list@lists.mulberrytech.com
Subject: RE: [xsl] replace function


e is get a string i.e.
> "steve,john,peter" and replace the next word to a comma  with
> a space hence the new string become "steve, john, peter" how
> can i achieve this using the translate function?

Although people have written solutions to this that you can use
off-the-shelf, it's worth learning how to write the code yourself. You
need a recursive template, it should use substring-before() to output
the string before the first comma, then output ", ", then use
substring-after() and call itself to process the rest of the string
after the first comma.

Any good XSLT textbook will have examples of this.

Michael Kay
Software AG
home: Michael.H.Kay@ntlworld.com
work: Michael.Kay@softwareag.com


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



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

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]