[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|