| Newsgroups |
gmane.text.xml.xsl.general.mulberrytech |
| Message-ID |
<[email protected]> |
--00000000000080260905be9c1e51
Content-Type: text/plain; charset="UTF-8"
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 [email protected] <
[email protected]> 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
>
> [email protected]
>
> 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.
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/3329386
or by email: [email protected]
--~--
--00000000000080260905be9c1e51
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Here is a multi-replace transformation I wrote as an answe=
r to this SO question in 2012 (no regex, just replace one whole string with=
another).<br><br>This is just a recursive algorithm:<br><br><a href=3D"htt=
ps://stackoverflow.com/a/12505924/36305">https://stackoverflow.com/a/125059=
24/36305</a><br><br>In the example there, it transforms:<br><br><pre class=
=3D"gmail-lang-xml gmail-s-code-block gmail-hljs" style=3D"margin-top:0px;p=
adding:12px;border:0px;font-variant-numeric:inherit;font-variant-east-asian=
:inherit;font-stretch:inherit;line-height:1.30769;font-family:Consolas,Menl=
o,Monaco,"Lucida Console","Liberation Mono","DejaV=
u Sans Mono","Bitstream Vera Sans Mono","Courier New&qu=
ot;,monospace,sans-serif;font-size:13px;vertical-align:baseline;box-sizing:=
inherit;width:auto;max-height:600px;overflow:auto;border-radius:5px"><code =
style=3D"margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:=
inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-f=
amily:inherit;vertical-align:baseline;box-sizing:inherit;background-color:t=
ransparent;white-space:inherit"><span class=3D"gmail-hljs-tag" style=3D"mar=
gin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font=
-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:inheri=
t;vertical-align:baseline;box-sizing:inherit"><<span class=3D"gmail-hljs=
-name" style=3D"margin:0px;padding:0px;border:0px;font-style:inherit;font-v=
ariant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit=
;font-family:inherit;vertical-align:baseline;box-sizing:inherit">t</span>&g=
t;</span>The quick
brown fox<span class=3D"gmail-hljs-tag" style=3D"margin:0px;padding:0px;bor=
der:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-st=
retch:inherit;line-height:inherit;font-family:inherit;vertical-align:baseli=
ne;box-sizing:inherit"></<span class=3D"gmail-hljs-name" style=3D"margin=
:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-we=
ight:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;v=
ertical-align:baseline;box-sizing:inherit">t</span>>
to:
<pre class=3D"gmail-lang-xml gmail-s-code-block gmail-hljs" style=3D"margin=
-top:0px;padding:12px;border:0px;font-variant-numeric:inherit;font-variant-=
east-asian:inherit;font-stretch:inherit;line-height:1.30769;font-family:Con=
solas,Menlo,Monaco,"Lucida Console","Liberation Mono",&=
quot;DejaVu Sans Mono","Bitstream Vera Sans Mono","Cour=
ier New",monospace,sans-serif;vertical-align:baseline;box-sizing:inher=
it;width:auto;max-height:600px;overflow:auto;border-radius:5px"><code style=
=3D"margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inher=
it;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family=
:inherit;vertical-align:baseline;box-sizing:inherit;background-color:transp=
arent;white-space:inherit">The slow<span class=3D"gmail-hljs-tag" style=3D"=
margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;f=
ont-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:inh=
erit;vertical-align:baseline;box-sizing:inherit"><<span class=3D"gmail-h=
ljs-name" style=3D"margin:0px;padding:0px;border:0px;font-style:inherit;fon=
t-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inhe=
rit;font-family:inherit;vertical-align:baseline;box-sizing:inherit">br</spa=
n> /></span>white elephant</code></pre></span></code></pre><div>:)</div>=
<br>Thanks,<div>Dimitre</div></div><br><div class=3D"gmail_quote"><div dir=
=3D"ltr" class=3D"gmail_attr">On Wed, Mar 24, 2021 at 1:28 PM <a href=3D"ma=
ilto:[email protected]">[email protected]</a> <<a href=3D"mailto:xsl=
[email protected]">[email protected]=
om</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margi=
n:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex=
"><div lang=3D"EN-US" style=3D"overflow-wrap: break-word;"><div class=3D"gm=
ail-m_-8259616194241297605WordSection1"><p class=3D"MsoNormal">Hello All,<u=
></u><u></u></p><p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p><p class=3D"=
MsoNormal">I have a fairly large XML file similar to this:<u></u><u></u></p=
><p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p><p class=3D"MsoNormal"><=
?xml version=3D"1.0" encoding=3D"UTF-8"?><u></u><u><=
/u></p><p class=3D"MsoNormal"><products><u></u><u></u></p><p class=3D=
"MsoNormal">=C2=A0=C2=A0=C2=A0 <product>ACME Wid Assbly</product&g=
t;<u></u><u></u></p><p class=3D"MsoNormal">=C2=A0=C2=A0=C2=A0 <product&g=
t;Ford Eng Rebuild Kit</product><u></u><u></u></p><p class=3D"MsoNorm=
al"></products><u></u><u></u></p><p class=3D"MsoNormal"><u></u>=C2=A0=
<u></u></p><p class=3D"MsoNormal">I want to do an identity transform except=
that I want to do some find and replace on some of the words. For example<=
u></u><u></u></p><p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p><p class=3D=
"MsoNormal">Wid =3D Widget<u></u><u></u></p><p class=3D"MsoNormal">Assbly =
=3D Assembly<u></u><u></u></p><p class=3D"MsoNormal">Eng =3D Engine<u></u><=
u></u></p><p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p><p class=3D"MsoNor=
mal">I am thinking of creating a lookup XML file to drive the find/replace =
actions:<u></u><u></u></p><p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p><p=
class=3D"MsoNormal"><?xml version=3D"1.0" encoding=3D"UT=
F-8"?><u></u><u></u></p><p class=3D"MsoNormal"><lookup><u></u=
><u></u></p><p class=3D"MsoNormal">=C2=A0=C2=A0=C2=A0 <entry find=3D&quo=
t;\bWid\b" replace=3D"Widget"/><u></u><u></u></p><p class=
=3D"MsoNormal">=C2=A0=C2=A0=C2=A0 <entry find=3D"\bAssbly\b" r=
eplace=3D"Assembly"/><u></u><u></u></p><p class=3D"MsoNormal">=
=C2=A0=C2=A0=C2=A0 <entry find=3D"\bEng\b" replace=3D"Eng=
ine"/><u></u><u></u></p><p class=3D"MsoNormal"></lookup><u></=
u><u></u></p><p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p><p class=3D"Mso=
Normal">I am having trouble figuring out a good XSLT 2 or 3 algorithm for a=
ctually doing the replacements. Any suggestions or pointers would be apprec=
iated. Thank you very much.<u></u><u></u></p><p class=3D"MsoNormal"><u></u>=
=C2=A0<u></u></p><p class=3D"MsoNormal">Rick<u></u><u></u></p><p class=3D"M=
soNormal"><u></u>=C2=A0<u></u></p><p class=3D"MsoNormal">Rick Quatro<u></u>=
<u></u></p><p class=3D"MsoNormal">Carmen Publishing Inc.<u></u><u></u></p><=
p class=3D"MsoNormal">585-729-6746<u></u><u></u></p><p class=3D"MsoNormal">=
<a href=3D"mailto:[email protected]" target=3D"_blank">rick@frameexpert.=
com</a><u></u><u></u></p><p class=3D"MsoNormal"><a href=3D"http://www.frame=
expert.com/store" target=3D"_blank">http://www.frameexpert.com/store</a><u>=
</u><u></u></p><p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p><p class=3D"M=
soNormal"><u></u>=C2=A0<u></u></p></div></div>
<div>
<div style=3D"border-top:1px solid black;background-color:rgb(221,221,221);=
color:rgb(136,136,136);font-size:smaller;padding:5px;text-align:center;font=
-family:arial,verdana,arial,sans-serif;clear:both;margin:auto">
<a href=3D"http://www.mulberrytech.com/xsl/xsl-list" target=3D"_blank">
XSL-List info and archive</a>
<div style=3D"text-align:center">
<a style=3D"color:blue" href=3D"http://lists.mulberrytech.com/unsub/xsl-lis=
t/782854" target=3D"_blank">EasyUnsubscribe</a>
(<a style=3D"color:blue" href=3D"" target=3D"_blank">by email</a>)
</div>
</div>
</div>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
class=3D"gmail_signature"><div>Cheers,</div><div>Dimitre Novatchev</div><d=
iv>---------------------------------------</div><div>Truly great madness ca=
nnot be achieved without significant intelligence.</div><div>--------------=
-------------------------</div><div>To invent, you need a good imagination =
and a pile of junk</div><div>-------------------------------------</div><di=
v>Never fight an inanimate object</div><div>-------------------------------=
------</div><div>To avoid situations in which you might make mistakes may b=
e the</div><div>biggest mistake of all</div><div>--------------------------=
----------</div><div>Quality means doing it right when no one is looking.</=
div><div>-------------------------------------</div><div>You've achieve=
d success in your field when you don't know whether what you're doi=
ng is work or play</div><div>-------------------------------------</div><di=
v>To achieve the impossible dream, try going to sleep.</div><div>----------=
---------------------------</div><div>Facts do not cease to exist because t=
hey are ignored.</div><div>-------------------------------------</div><div>=
Typing monkeys will write all Shakespeare's works in 200yrs.Will they w=
rite all patents, too? :)</div><div>-------------------------------------</=
div><div>Sanity is madness put to good use.</div><div>---------------------=
----------------</div><div>I finally figured out the only reason to be aliv=
e is to enjoy it.</div><div>=C2=A0</div></div>
<div><!-- begin bl.html.trailer -->
<div style=3D"border-top:1px solid black; background-color: #dddddd;
color: #888888; font-size: smaller; padding: 5px; text-align: center;
font-family: arial,verdana,arial,sans-serif; margin-top:1em; clear:
both; margin: auto">
<a href=3D"http://www.mulberrytech.com/xsl/xsl-list">
XSL-List info and archive</a>
<div style=3D"text-align:center;">
<a style=3D"color: blue;"
href=3D"http://lists.mulberrytech.com/unsub/xsl-list/3329386"
>EasyUnsubscribe</a>
(<a style=3D"color: blue;"
href=3D"mailto:[email protected]?subject=3Dremove"
>by email</a>)
</div>
</div>
<!-- end bl.html.trailer --></div>
--00000000000080260905be9c1e51--