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

RE: replace function

Subject: RE: replace function
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Mon, 30 Sep 2002 10:49:43 -0700 (PDT)
xml replace function
"Stevenson Ngila" <Stevenson at epr dot footman-walker dot com> wrote:

> All what i want to achieve 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?

The translate() function can be used to perform only 1:1 or 1:0
character replacement. What you want here is 1 : 2.

Using the "str-map" template from FXSL, this is done in a most
straightforward manner:

stylesheet:
----------
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:testmap="f:testmap"
>
   <xsl:import href="str-map.xsl"/>
   
   <xsl:output method="text"/>
   
   <!-- to be applied on any xml source -->
   
   <testmap:testmap/>

   <xsl:output omit-xml-declaration="yes" indent="yes"/>
   
   <xsl:template match="/">
     <xsl:variable name="vTestMap" 
                   select="document('')/*/testmap:*[1]"/>
     <xsl:call-template name="str-map">
       <xsl:with-param name="pFun" select="$vTestMap"/>
       <xsl:with-param name="pStr" select="'steve,john,peter'"/>
     </xsl:call-template>
   </xsl:template>

    <xsl:template name="replAmpersand" match="testmap:*">
      <xsl:param name="arg1"/>
      
      <xsl:copy-of select="$arg1"/>
      <xsl:if test="$arg1 = ','">
        <xsl:value-of select="' '"/>
      </xsl:if>

    </xsl:template>

</xsl:stylesheet>


When applied on any source xml document, the result is:

steve, john, peter


Hope this helped.




=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com

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


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.