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

Re: replace-string() convenience function proposal

Subject: Re: replace-string() convenience function proposal
From: Joe English <jenglish@xxxxxxxxxxxxx>
Date: Thu, 31 Aug 2000 09:51:51 -0700
tcl string replace function
Evan Lenz wrote:
>
> I would like a function such as replace-string() that would allow me to
> replace one specified string with another specified string, within a
> specified string.  For example, replace-string("Hello there", "Hello", "Hi")
> would return "Hi there".  I use the following stylesheet (adapted from an
> example in Kay's book) to do this for me now.
> [ ... screenful of code snipped ]
> The translate() function is great for one-to-one character replacements, but
> as soon as you want to replace a character with, say, two characters

... or even harder, replacing two or more characters with another string ...

> (as in
> my example), you have to write a named template that recursively calls
> itself, and pass all the parameters via <xsl:with-param/> each time you need
> to call it, which, as you can see, can get quite ugly.
>
> I don't care what this function is called; maybe just replace() would be
> better.
>
> Anyone want to second this motion (assuming it hasn't already been
> proposed)?


Seconded!

Tcl 8.2 and up has a [string map] function that does
multiple simultaneous string-to-string substitutions
in a single pass; Cost has a [substitution] command
that does much the same thing.  This function is *absolutely
indispensable* for converting XML/SGML to other markup
notations.  It's also a heck of a lot easier to implement
than a full regexp/regsub engine, and considerably easier
to use too.  Something like this would be a very useful
addition to XSLT.


--Joe English

  jenglish@xxxxxxxxxxxxx


 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.