Re: Find/replace algorithm

"Paul Tyson [email protected]" <[email protected]> Thu, 25 Mar 2021 03:03:38 -0000
Newsgroups gmane.text.xml.xsl.general.mulberrytech
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------D98B26A60519BF0A4B7620BB
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 8bit

Is it coincidence that your examples are all approximate string matches? 
If not, an alternate multi-stage approach might be to check all 
non-words for approximate match to target list, followed by find and 
replace operation. Open-source libraries are available for approximate 
string matching.

https://en.wikipedia.org/wiki/Approximate_string_matching

Regards,

--Paul

On 3/24/21 3:28 PM, [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] <mailto:[email protected]>
>
> http://www.frameexpert.com/store <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/1043515> 
> (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]
--~--

--------------D98B26A60519BF0A4B7620BB
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: 8bit

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;
      charset=windows-1252">
  </head>
  <body>
    <p>Is it coincidence that your examples are all approximate string
      matches? If not, an alternate multi-stage approach might be to
      check all non-words for approximate match to target list, followed
      by find and replace operation. Open-source libraries are available
      for approximate string matching.</p>
    <p><a class="moz-txt-link-freetext" href="https://en.wikipedia.org/wiki/Approximate_string_matching">https://en.wikipedia.org/wiki/Approximate_string_matching</a></p>
    <p>Regards,</p>
    <p>--Paul<br>
    </p>
    <div class="moz-cite-prefix">On 3/24/21 3:28 PM, <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
      wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:[email protected]">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      <meta name="Generator" content="Microsoft Word 15 (filtered
        medium)">
      <style>@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	font-size:11.0pt;
	font-family:"Calibri",sans-serif;}span.EmailStyle17
	{mso-style-type:personal-compose;
	font-family:"Calibri",sans-serif;
	color:windowtext;}.MsoChpDefault
	{mso-style-type:export-only;
	font-family:"Calibri",sans-serif;}div.WordSection1
	{page:WordSection1;}</style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
      <div class="WordSection1">
        <p class="MsoNormal">Hello All,<o:p></o:p></p>
        <p class="MsoNormal"><o:p>�</o:p></p>
        <p class="MsoNormal">I have a fairly large XML file similar to
          this:<o:p></o:p></p>
        <p class="MsoNormal"><o:p>�</o:p></p>
        <p class="MsoNormal">&lt;?xml version="1.0"
          encoding="UTF-8"?&gt;<o:p></o:p></p>
        <p class="MsoNormal">&lt;products&gt;<o:p></o:p></p>
        <p class="MsoNormal">��� &lt;product&gt;ACME Wid
          Assbly&lt;/product&gt;<o:p></o:p></p>
        <p class="MsoNormal">��� &lt;product&gt;Ford Eng Rebuild
          Kit&lt;/product&gt;<o:p></o:p></p>
        <p class="MsoNormal">&lt;/products&gt;<o:p></o:p></p>
        <p class="MsoNormal"><o:p>�</o:p></p>
        <p class="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<o:p></o:p></p>
        <p class="MsoNormal"><o:p>�</o:p></p>
        <p class="MsoNormal">Wid = Widget<o:p></o:p></p>
        <p class="MsoNormal">Assbly = Assembly<o:p></o:p></p>
        <p class="MsoNormal">Eng = Engine<o:p></o:p></p>
        <p class="MsoNormal"><o:p>�</o:p></p>
        <p class="MsoNormal">I am thinking of creating a lookup XML file
          to drive the find/replace actions:<o:p></o:p></p>
        <p class="MsoNormal"><o:p>�</o:p></p>
        <p class="MsoNormal">&lt;?xml version="1.0"
          encoding="UTF-8"?&gt;<o:p></o:p></p>
        <p class="MsoNormal">&lt;lookup&gt;<o:p></o:p></p>
        <p class="MsoNormal">��� &lt;entry find="\bWid\b"
          replace="Widget"/&gt;<o:p></o:p></p>
        <p class="MsoNormal">��� &lt;entry find="\bAssbly\b"
          replace="Assembly"/&gt;<o:p></o:p></p>
        <p class="MsoNormal">��� &lt;entry find="\bEng\b"
          replace="Engine"/&gt;<o:p></o:p></p>
        <p class="MsoNormal">&lt;/lookup&gt;<o:p></o:p></p>
        <p class="MsoNormal"><o:p>�</o:p></p>
        <p class="MsoNormal">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.<o:p></o:p></p>
        <p class="MsoNormal"><o:p>�</o:p></p>
        <p class="MsoNormal">Rick<o:p></o:p></p>
        <p class="MsoNormal"><o:p>�</o:p></p>
        <p class="MsoNormal">Rick Quatro<o:p></o:p></p>
        <p class="MsoNormal">Carmen Publishing Inc.<o:p></o:p></p>
        <p class="MsoNormal">585-729-6746<o:p></o:p></p>
        <p class="MsoNormal"><a href="mailto:[email protected]"
            moz-do-not-send="true">[email protected]</a><o:p></o:p></p>
        <p class="MsoNormal"><a href="http://www.frameexpert.com/store"
            moz-do-not-send="true">http://www.frameexpert.com/store</a><o:p></o:p></p>
        <p class="MsoNormal"><o:p>�</o:p></p>
        <p class="MsoNormal"><o:p>�</o:p></p>
      </div>
      <div><!-- begin bl.html.trailer -->
        <div style="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="http://www.mulberrytech.com/xsl/xsl-list"
            moz-do-not-send="true">
            XSL-List info and archive</a>
          <div style="text-align:center;">
            <a style="color: blue;"
              href="http://lists.mulberrytech.com/unsub/xsl-list/1043515"
              moz-do-not-send="true">EasyUnsubscribe</a>
            (<a style="color: blue;"
              href=""
              moz-do-not-send="true">by email</a>)
          </div>
        </div>
        <!-- end bl.html.trailer --></div>
    </blockquote>
  </body>
</html>
<div><!-- begin bl.html.trailer -->
<div style="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="http://www.mulberrytech.com/xsl/xsl-list">
XSL-List info and archive</a>
<div style="text-align:center;">
<a style="color: blue;"
  href="http://lists.mulberrytech.com/unsub/xsl-list/3329386"
>EasyUnsubscribe</a>
(<a style="color: blue;"
href="mailto:[email protected]?subject=remove"
>by email</a>)
</div>
</div>
<!-- end bl.html.trailer --></div>

--------------D98B26A60519BF0A4B7620BB--