Re: Find/replace algorithm

"Chris Papademetrious [email protected]" <[email protected]> Thu, 25 Mar 2021 16:36:07 -0000
Newsgroups gmane.text.xml.xsl.general.mulberrytech
Message-ID <[email protected]>
--_000_DM6PR12MB4154201FD33B7EE9E6A468B3DD629DM6PR12MB4154namp_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hi Rick,

I'm a noob so this may not be the best answer. For free-form regsubs that a=
ren't on word boundaries, maybe you could pass your sequence of <entry> nod=
es to an XSLT function, then that function applies the first <entry> and ca=
lls itself with the remainder? Then you could use this function to apply al=
l substitutions from a suitable template.

Of course, this is brute force and inefficient. But I don't know how else t=
o handle an arbitrary list of free-form regsubs. I suspect that the cost to=
 pre-screen for a match is the same as the cost to attempt the substitution.


  *   Chris

From: [email protected] <[email protected]>
Sent: Thursday, March 25, 2021 12:29 PM
To: [email protected]
Subject: Re: [xsl] Find/replace algorithm

Thank you Michael. I like the idea of keeping the processing cost constant =
but I was going to use regular expressions in my map, so I may still have t=
o loop through the lookup structure.

From: Michael Kay [email protected]<mailto:[email protected]> <xsl-list-ser=
[email protected]<mailto:[email protected]>>
Sent: Wednesday, March 24, 2021 7:48 PM
To: xsl-list <[email protected]<mailto:[email protected]=
ytech.com>>
Subject: Re: [xsl] Find/replace algorithm

My instinct would be

(a) build a map containing the replacements

(b) for each text node, tokenize the content, then scan the tokens looking =
each one up in the map.

The big advantage of this approach is that the cost is constant regardless =
how many substitutions there are, whereas most other approaches have a cost=
 that increases linearly with the number of substitutions.

Michael Kay
Saxonica
EasyUnsubscribe<https://urldefense.com/v3/__http:/lists.mulberrytech.com/un=
sub/xsl-list/612310__;!!A4F2R9G_pg!OjZv4pOytV-MHnnYzmpZEWsTCp9w_XI7Yyg96Pzh=
L59tGen5qlBh1A78_VDXguo9h6eSCQiTqAhIqMA$> (by email)
XSL-List info and archive<https://urldefense.com/v3/__http:/www.mulberrytec=
h.com/xsl/xsl-list__;!!A4F2R9G_pg!OjZv4pOytV-MHnnYzmpZEWsTCp9w_XI7Yyg96PzhL=
59tGen5qlBh1A78_VDXguo9h6eSCQiTRK-dOrQ$>
EasyUnsubscribe<https://urldefense.com/v3/__http:/lists.mulberrytech.com/un=
sub/xsl-list/3380743__;!!A4F2R9G_pg!OjZv4pOytV-MHnnYzmpZEWsTCp9w_XI7Yyg96Pz=
hL59tGen5qlBh1A78_VDXguo9h6eSCQiTgWCRb9c$> (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]
--~--

--_000_DM6PR12MB4154201FD33B7EE9E6A468B3DD629DM6PR12MB4154namp_
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-micr=
osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" xmlns=3D"http:=
//www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii">
<meta name=3D"Generator" content=3D"Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
	{font-family:Wingdings;
	panose-1:5 0 0 0 0 0 0 0 0 0;}
@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;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
	{mso-style-priority:34;
	margin-top:0in;
	margin-right:0in;
	margin-bottom:0in;
	margin-left:.5in;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri",sans-serif;}
span.EmailStyle20
	{mso-style-type:personal-reply;
	font-family:"Calibri",sans-serif;
	color:windowtext;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
/* List Definitions */
@list l0
	{mso-list-id:1182740041;
	mso-list-type:hybrid;
	mso-list-template-ids:-1671381252 -101410664 67698691 67698693 67698689 67=
698691 67698693 67698689 67698691 67698693;}
@list l0:level1
	{mso-level-start-at:0;
	mso-level-number-format:bullet;
	mso-level-text:-;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	margin-left:20.25pt;
	text-indent:-.25in;
	font-family:"Calibri",sans-serif;
	mso-fareast-font-family:Calibri;}
@list l0:level2
	{mso-level-number-format:bullet;
	mso-level-text:o;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	margin-left:56.25pt;
	text-indent:-.25in;
	font-family:"Courier New";}
@list l0:level3
	{mso-level-number-format:bullet;
	mso-level-text:\F0A7;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	margin-left:92.25pt;
	text-indent:-.25in;
	font-family:Wingdings;}
@list l0:level4
	{mso-level-number-format:bullet;
	mso-level-text:\F0B7;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	margin-left:128.25pt;
	text-indent:-.25in;
	font-family:Symbol;}
@list l0:level5
	{mso-level-number-format:bullet;
	mso-level-text:o;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	margin-left:164.25pt;
	text-indent:-.25in;
	font-family:"Courier New";}
@list l0:level6
	{mso-level-number-format:bullet;
	mso-level-text:\F0A7;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	margin-left:200.25pt;
	text-indent:-.25in;
	font-family:Wingdings;}
@list l0:level7
	{mso-level-number-format:bullet;
	mso-level-text:\F0B7;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	margin-left:236.25pt;
	text-indent:-.25in;
	font-family:Symbol;}
@list l0:level8
	{mso-level-number-format:bullet;
	mso-level-text:o;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	margin-left:272.25pt;
	text-indent:-.25in;
	font-family:"Courier New";}
@list l0:level9
	{mso-level-number-format:bullet;
	mso-level-text:\F0A7;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	margin-left:308.25pt;
	text-indent:-.25in;
	font-family:Wingdings;}
ol
	{margin-bottom:0in;}
ul
	{margin-bottom:0in;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=3D"EN-US" link=3D"blue" vlink=3D"purple">
<div class=3D"WordSection1">
<p class=3D"MsoNormal">Hi Rick,<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">I&#8217;m a noob so this may not be the best answer.=
 For free-form regsubs that aren&#8217;t on word boundaries, maybe you coul=
d pass your sequence of &lt;entry&gt; nodes to an XSLT function, then that =
function applies the first &lt;entry&gt; and calls itself
 with the remainder? Then you could use this function to apply all substitu=
tions from a suitable template.<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">Of course, this is brute force and inefficient. But =
I don&#8217;t know how else to handle an arbitrary list of free-form regsub=
s. I suspect that the cost to pre-screen for a match is the same as the cos=
t to attempt the substitution.<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<ul style=3D"margin-top:0in" type=3D"disc">
<li class=3D"MsoListParagraph" style=3D"margin-left:-15.75pt;mso-list:l0 le=
vel1 lfo1">
Chris<o:p></o:p></li></ul>
<p class=3D"MsoNormal"><o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<div style=3D"border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in =
0in 0in">
<p class=3D"MsoNormal"><b>From:</b> [email protected] &lt;xsl-list-servic=
[email protected]&gt;
<br>
<b>Sent:</b> Thursday, March 25, 2021 12:29 PM<br>
<b>To:</b> [email protected]<br>
<b>Subject:</b> Re: [xsl] Find/replace algorithm<o:p></o:p></p>
</div>
</div>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">Thank you Michael. I like the idea of keeping the pr=
ocessing cost constant but I was going to use regular expressions in my map=
, so I may still have to loop through the lookup structure.<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<div style=3D"border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in =
0in 0in">
<p class=3D"MsoNormal"><b>From:</b> Michael Kay <a href=3D"mailto:mike@saxo=
nica.com">
[email protected]</a> &lt;<a href=3D"mailto:[email protected]=
tech.com">[email protected]</a>&gt;
<br>
<b>Sent:</b> Wednesday, March 24, 2021 7:48 PM<br>
<b>To:</b> xsl-list &lt;<a href=3D"mailto:[email protected]">=
[email protected]</a>&gt;<br>
<b>Subject:</b> Re: [xsl] Find/replace algorithm<o:p></o:p></p>
</div>
</div>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">My instinct would be&nbsp;<o:p></o:p></p>
<div>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class=3D"MsoNormal">(a) build a map containing the replacements<o:p></o:=
p></p>
</div>
<div>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class=3D"MsoNormal">(b) for each text node, tokenize the content, then s=
can the tokens looking each one up in the map.<o:p></o:p></p>
</div>
<div>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class=3D"MsoNormal">The big advantage of this approach is that the cost =
is constant regardless how many substitutions there are, whereas most other=
 approaches have a cost that increases linearly with the number of substitu=
tions.<o:p></o:p></p>
</div>
<div>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class=3D"MsoNormal">Michael Kay<o:p></o:p></p>
</div>
<div>
<p class=3D"MsoNormal">Saxonica<o:p></o:p></p>
</div>
<div>
<div style=3D"border:none;border-top:solid black 1.0pt;padding:4.0pt 0in 0i=
n 0in;margin-top:5.0pt;margin-bottom:5.0pt">
<p class=3D"MsoNormal" align=3D"center" style=3D"text-align:center;backgrou=
nd:#DDDDDD">
<span style=3D"font-size:7.5pt;font-family:&quot;Arial&quot;,sans-serif;col=
or:#888888"><a href=3D"https://urldefense.com/v3/__http:/lists.mulberrytech=
.com/unsub/xsl-list/612310__;!!A4F2R9G_pg!OjZv4pOytV-MHnnYzmpZEWsTCp9w_XI7Y=
yg96PzhL59tGen5qlBh1A78_VDXguo9h6eSCQiTqAhIqMA$">EasyUnsubscribe</a>
 (<span class=3D"MsoHyperlink">by email</span>) <o:p></o:p></span></p>
</div>
</div>
<div>
<div style=3D"border:none;border-top:solid black 1.0pt;padding:4.0pt 0in 0i=
n 0in;margin-top:5.0pt;margin-bottom:5.0pt">
<p class=3D"MsoNormal" align=3D"center" style=3D"text-align:center;backgrou=
nd:#DDDDDD">
<span style=3D"font-size:7.5pt;font-family:&quot;Arial&quot;,sans-serif;col=
or:#888888"><a href=3D"https://urldefense.com/v3/__http:/www.mulberrytech.c=
om/xsl/xsl-list__;!!A4F2R9G_pg!OjZv4pOytV-MHnnYzmpZEWsTCp9w_XI7Yyg96PzhL59t=
Gen5qlBh1A78_VDXguo9h6eSCQiTRK-dOrQ$">XSL-List
 info and archive</a> <o:p></o:p></span></p>
<p class=3D"MsoNormal" align=3D"center" style=3D"text-align:center;backgrou=
nd:#DDDDDD">
<span style=3D"font-size:7.5pt;font-family:&quot;Arial&quot;,sans-serif;col=
or:#888888"><a href=3D"https://urldefense.com/v3/__http:/lists.mulberrytech=
.com/unsub/xsl-list/3380743__;!!A4F2R9G_pg!OjZv4pOytV-MHnnYzmpZEWsTCp9w_XI7=
Yyg96PzhL59tGen5qlBh1A78_VDXguo9h6eSCQiTgWCRb9c$">EasyUnsubscribe</a>
 (<a href=3D"">by email</a>)
<o:p></o:p></span></p>
</div>
</div>
</div>
</body>
</html>
<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>

--_000_DM6PR12MB4154201FD33B7EE9E6A468B3DD629DM6PR12MB4154namp_--