Re: Find/replace algorithm

"David Carlisle [email protected]" <[email protected]> Wed, 24 Mar 2021 20:56:35 -0000
Newsgroups gmane.text.xml.xsl.general.mulberrytech
Message-ID <[email protected]>
--000000000000c1f8a705be4e8748
Content-Type: text/plain; charset="UTF-8"

I know this is xsl-list but have you considered

$ sed -e 's/\bWid\b/Widget/g' -e 's/\bAssbly\b/Assembly/g' -e
's/\bEng\b/Engine/g' zz1.xml
<?xml version="1.0" encoding="UTF-8"?>

<products>

    <product>ACME Widget Assembly</product>

    <product>Ford Engine Rebuild Kit</product>

</products>

On Wed, 24 Mar 2021 at 20:28, [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/2739265> (by
> email <>)
>
--~----------------------------------------------------------------
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]
--~--

--000000000000c1f8a705be4e8748
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I know this is xsl-list but have you considered</div>=
<div><br></div><div>$ sed -e &#39;s/\bWid\b/Widget/g&#39; -e &#39;s/\bAssbl=
y\b/Assembly/g&#39; -e &#39;s/\bEng\b/Engine/g&#39; zz1.xml<br>&lt;?xml ver=
sion=3D&quot;1.0&quot; encoding=3D&quot;UTF-8&quot;?&gt;<br><br>&lt;product=
s&gt;<br><br>=C2=A0 =C2=A0 &lt;product&gt;ACME Widget Assembly&lt;/product&=
gt;<br><br>=C2=A0 =C2=A0 &lt;product&gt;Ford Engine Rebuild Kit&lt;/product=
&gt;<br><br>&lt;/products&gt;</div></div><br><div class=3D"gmail_quote"><di=
v dir=3D"ltr" class=3D"gmail_attr">On Wed, 24 Mar 2021 at 20:28, <a href=3D=
"mailto:[email protected]">[email protected]</a> &lt;<a href=3D"mailto:=
[email protected]">[email protected]=
h.com</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"ma=
rgin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:=
1ex"><div style=3D"overflow-wrap: break-word;" lang=3D"EN-US"><div class=3D=
"gmail-m_8054368320538244912WordSection1"><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">=
&lt;?xml version=3D&quot;1.0&quot; encoding=3D&quot;UTF-8&quot;?&gt;<u></u>=
<u></u></p><p class=3D"MsoNormal">&lt;products&gt;<u></u><u></u></p><p clas=
s=3D"MsoNormal">=C2=A0=C2=A0=C2=A0 &lt;product&gt;ACME Wid Assbly&lt;/produ=
ct&gt;<u></u><u></u></p><p class=3D"MsoNormal">=C2=A0=C2=A0=C2=A0 &lt;produ=
ct&gt;Ford Eng Rebuild Kit&lt;/product&gt;<u></u><u></u></p><p class=3D"Mso=
Normal">&lt;/products&gt;<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 ex=
ample<u></u><u></u></p><p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p><p cl=
ass=3D"MsoNormal">Wid =3D Widget<u></u><u></u></p><p class=3D"MsoNormal">As=
sbly =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"M=
soNormal">I am thinking of creating a lookup XML file to drive the find/rep=
lace actions:<u></u><u></u></p><p class=3D"MsoNormal"><u></u>=C2=A0<u></u><=
/p><p class=3D"MsoNormal">&lt;?xml version=3D&quot;1.0&quot; encoding=3D&qu=
ot;UTF-8&quot;?&gt;<u></u><u></u></p><p class=3D"MsoNormal">&lt;lookup&gt;<=
u></u><u></u></p><p class=3D"MsoNormal">=C2=A0=C2=A0=C2=A0 &lt;entry find=
=3D&quot;\bWid\b&quot; replace=3D&quot;Widget&quot;/&gt;<u></u><u></u></p><=
p class=3D"MsoNormal">=C2=A0=C2=A0=C2=A0 &lt;entry find=3D&quot;\bAssbly\b&=
quot; replace=3D&quot;Assembly&quot;/&gt;<u></u><u></u></p><p class=3D"MsoN=
ormal">=C2=A0=C2=A0=C2=A0 &lt;entry find=3D&quot;\bEng\b&quot; replace=3D&q=
uot;Engine&quot;/&gt;<u></u><u></u></p><p class=3D"MsoNormal">&lt;/lookup&g=
t;<u></u><u></u></p><p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p><p class=
=3D"MsoNormal">I am having trouble figuring out a good XSLT 2 or 3 algorith=
m for actually doing the replacements. Any suggestions or pointers would be=
 appreciated. 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 cla=
ss=3D"MsoNormal"><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"MsoN=
ormal"><a href=3D"mailto:[email protected]" target=3D"_blank">rick@frame=
expert.com</a><u></u><u></u></p><p class=3D"MsoNormal"><a href=3D"http://ww=
w.frameexpert.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 cla=
ss=3D"MsoNormal"><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/2739265" target=3D"_blank">EasyUnsubscribe</a>
(<a style=3D"color:blue" href=3D"" target=3D"_blank">by email</a>)
</div>
</div>
</div>
</blockquote></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>

--000000000000c1f8a705be4e8748--