Subject: Re: [xsl] Find/replace algorithm From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sun, 28 Mar 2021 17:30:38 -0000 |
Here is a multi-replace transformation I wrote as an answer to this SO question in 2012 (no regex, just replace one whole string with another). This is just a recursive algorithm: https://stackoverflow.com/a/12505924/36305 In the example there, it transforms: <t>The quick brown fox</t> to: The slow<br />white elephant :) Thanks, Dimitre On Wed, Mar 24, 2021 at 1:28 PM rick@xxxxxxxxxxxxxx < xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > Hello All, > > > > I have a fairly large XML file similar to this: > > > > <?xml version="1.0" encoding="UTF-8"?> > > <products> > > <product>ACME Wid Assbly</product> > > <product>Ford Eng Rebuild Kit</product> > > </products> > > > > I want to do an identity transform except that I want to do some find and > replace on some of the words. For example > > > > Wid = Widget > > Assbly = Assembly > > Eng = Engine > > > > I am thinking of creating a lookup XML file to drive the find/replace > actions: > > > > <?xml version="1.0" encoding="UTF-8"?> > > <lookup> > > <entry find="\bWid\b" replace="Widget"/> > > <entry find="\bAssbly\b" replace="Assembly"/> > > <entry find="\bEng\b" replace="Engine"/> > > </lookup> > > > > I am having trouble figuring out a good XSLT 2 or 3 algorithm for actually > doing the replacements. Any suggestions or pointers would be appreciated. > Thank you very much. > > > > Rick > > > > Rick Quatro > > Carmen Publishing Inc. > > 585-729-6746 > > rick@xxxxxxxxxxxxxxx > > http://www.frameexpert.com/store > > > > > XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list> > EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/782854> (by > email <>) > -- Cheers, Dimitre Novatchev --------------------------------------- Truly great madness cannot be achieved without significant intelligence. --------------------------------------- To invent, you need a good imagination and a pile of junk ------------------------------------- Never fight an inanimate object ------------------------------------- To avoid situations in which you might make mistakes may be the biggest mistake of all ------------------------------------ Quality means doing it right when no one is looking. ------------------------------------- You've achieved success in your field when you don't know whether what you're doing is work or play ------------------------------------- To achieve the impossible dream, try going to sleep. ------------------------------------- Facts do not cease to exist because they are ignored. ------------------------------------- Typing monkeys will write all Shakespeare's works in 200yrs.Will they write all patents, too? :) ------------------------------------- Sanity is madness put to good use. ------------------------------------- I finally figured out the only reason to be alive is to enjoy it.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Find/replace algorithm, Paul Tyson phtyson@x | Thread | Re: [xsl] RDF graph to SVG force-di, Martynas Jusevičius |
Re: [xsl] Find/replace algorithm, Joel Kalvesmaki dire | Date | Re: [xsl] RDF graph to SVG force-di, Martynas Jusevičius |
Month |