|
Subject: Re: replace-string() convenience function proposal From: Joe English <jenglish@xxxxxxxxxxxxx> Date: Thu, 31 Aug 2000 09:51:51 -0700 |
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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: left zero pad digit string, robin | Thread | Confused with current context, Lee Barwick |
| Re: Hexadecimal Arithmetic, David Carlisle | Date | RE: Hexadecimal Arithmetic, Chris Bayes |
| Month |