Re: How to correctly position breaks in mixed content?

"Geert Bormans [email protected]" <[email protected]> Wed, 14 Apr 2021 09:55:14 -0000
Newsgroups gmane.text.xml.xsl.general.mulberrytech
Message-ID <[email protected]>
--=_a6fb6b41-f7f4-41ad-8866-57cf9bae99b7
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Hi Trevor,=20

One option would be to replace the mixed content elements by empty elements=
=20
<var>n<superscript>th</superscript></var>=20
to become=20
<var type=3D"s" id=3D"ID01"/>n<superscript type=3D"s" id=3D"ID02"/ >th<supe=
rscript type=3D"e" id=3D"ID02" ><var type=3D"r" id=3D"ID01"/>=20

if so all your characters are siblings, so can do a line breaking algorithm=
, preserving the empty elements=20
after that you simply reconstruct the elements=20

Met vriendelijke groeten,=20
Best regards,=20

Geert Bormans=20

----- Op 14 apr 2021 om 11:46 schreef Trevor Nicholls trevor@castingthevoid=
.com <[email protected]>:=20



NB currently XSL 2.0=20



I'm struggling with what I thought would be a simple enough problem:=20



given content like this=20



"<code>Mixed content, mainly text but with some text such as <var>variable =
names</var> wrapped in elements, sometimes nested like a reference to the <=
var>n<superscript>th</superscript></var> occurrence.</code>"=20



and a constraint that code should be rendered within a fixed width box, I n=
eed to come up with a template which will process the <code> element and tr=
ansform it into its word-wrapped equivalent.=20



I don't need to concern myself with character sizes or styles; the output o=
f this transformation will always be rendered in a fixed-width font.=20



I can write something which works fine if a <code> element is simple text -=
 but the requirement is for this to work with mixed content too. In the abo=
ve example, if the constraint is that the line must wrap at or before 64 ch=
aracters, the first break comes in the middle of the first <var>.=20



Assuming that the <code> example above is the current element, what I am tr=
ying to write is a template=20



<xsl:template name=3D"wordwrap">=20

<xsl:param name=3D"input" select=3D"." />=20

<xsl:param name=3D"linelen" select=3D"64" />=20

=E2=80=A6=20

</xsl:template>=20



that will output=20



"Mixed content, mainly text but with some text such as <var>variable</var><=
wordwrap/>=20

<var>names</var> wrapped in elements, sometimes nexted like a reference to<=
wordwrap/>=20

the <var>n<superscript>th</superscript></var> occurrence."=20



Can anyone offer me some pointers as to how I should implement this?=20



Cheers=20

T=20
[ http://www.mulberrytech.com/xsl/xsl-list |=20
XSL-List info and archive ]=20
[ http://lists.mulberrytech.com/unsub/xsl-list/554170 | EasyUnsubscribe ] (=
 [  | by email ] )=20
--~----------------------------------------------------------------
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]
--~--

--=_a6fb6b41-f7f4-41ad-8866-57cf9bae99b7
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<html><body><div style=3D"font-family: Arial; font-size: 10pt; color: #0000=
00"><div>Hi Trevor,</div><div><br data-mce-bogus=3D"1"></div><div>One optio=
n would be to replace the mixed content elements by empty elements</div><di=
v><!--StartFragment--><span style=3D"color: #000000; font-family: Calibri, =
sans-serif; font-size: 14.6667px; font-style: normal; font-variant-ligature=
s: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: nor=
mal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none;=
 white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-wid=
th: 0px; background-color: #ffffff; text-decoration-thickness: initial; tex=
t-decoration-style: initial; text-decoration-color: initial; display: inlin=
e !important; float: none;" data-mce-style=3D"color: #000000; font-family: =
Calibri, sans-serif; font-size: 14.6667px; font-style: normal; font-variant=
-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spa=
cing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transfo=
rm: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-s=
troke-width: 0px; background-color: #ffffff; text-decoration-thickness: ini=
tial; text-decoration-style: initial; text-decoration-color: initial; displ=
ay: inline !important; float: none;">&lt;var&gt;n&lt;superscript&gt;th&lt;/=
superscript&gt;&lt;/var&gt;</span><!--EndFragment--><div style=3D"clear: bo=
th;" data-mce-style=3D"clear: both;">to become</div><div style=3D"clear: bo=
th;" data-mce-style=3D"clear: both;"><!--StartFragment--><span style=3D"col=
or: #000000; font-family: Calibri, sans-serif; font-size: 14.6667px; font-s=
tyle: normal; font-variant-ligatures: normal; font-variant-caps: normal; fo=
nt-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text=
-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-sp=
acing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text=
-decoration-thickness: initial; text-decoration-style: initial; text-decora=
tion-color: initial; display: inline !important; float: none;" data-mce-sty=
le=3D"color: #000000; font-family: Calibri, sans-serif; font-size: 14.6667p=
x; font-style: normal; font-variant-ligatures: normal; font-variant-caps: n=
ormal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: st=
art; text-indent: 0px; text-transform: none; white-space: normal; widows: 2=
; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #fff=
fff; text-decoration-thickness: initial; text-decoration-style: initial; te=
xt-decoration-color: initial; display: inline !important; float: none;"><sp=
an style=3D"color: #000000; font-family: Calibri, sans-serif; font-size: 14=
.6667px; font-style: normal; font-variant-ligatures: normal; font-variant-c=
aps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-ali=
gn: start; text-indent: 0px; text-transform: none; white-space: normal; wid=
ows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color=
: #ffffff; text-decoration-thickness: initial; text-decoration-style: initi=
al; text-decoration-color: initial; display: inline !important; float: none=
;" data-mce-style=3D"color: #000000; font-family: Calibri, sans-serif; font=
-size: 14.6667px; font-style: normal; font-variant-ligatures: normal; font-=
variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2;=
 text-align: start; text-indent: 0px; text-transform: none; white-space: no=
rmal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; backgro=
und-color: #ffffff; text-decoration-thickness: initial; text-decoration-sty=
le: initial; text-decoration-color: initial; display: inline !important; fl=
oat: none;"><span style=3D"color: #000000; font-family: Calibri, sans-serif=
; font-size: 14.6667px; font-style: normal; font-variant-ligatures: normal;=
 font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orpha=
ns: 2; text-align: start; text-indent: 0px; text-transform: none; white-spa=
ce: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; b=
ackground-color: #ffffff; text-decoration-thickness: initial; text-decorati=
on-style: initial; text-decoration-color: initial; display: inline !importa=
nt; float: none;" data-mce-style=3D"color: #000000; font-family: Calibri, s=
ans-serif; font-size: 14.6667px; font-style: normal; font-variant-ligatures=
: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: norm=
al; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; =
white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-widt=
h: 0px; background-color: #ffffff; text-decoration-thickness: initial; text=
-decoration-style: initial; text-decoration-color: initial; display: inline=
 !important; float: none;">&lt;var type=3D"s" id=3D"ID01"/&gt;n&lt;superscr=
ipt <!--StartFragment--><span>&nbsp;</span>type=3D"s" id=3D"ID02"/</span></=
span></span><span style=3D"color: #000000; font-family: Calibri, sans-serif=
; font-size: 14.6667px; font-style: normal; font-variant-ligatures: normal;=
 font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orpha=
ns: 2; text-align: start; text-indent: 0px; text-transform: none; white-spa=
ce: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; b=
ackground-color: #ffffff; text-decoration-thickness: initial; text-decorati=
on-style: initial; text-decoration-color: initial; display: inline !importa=
nt; float: none;" data-mce-style=3D"color: #000000; font-family: Calibri, s=
ans-serif; font-size: 14.6667px; font-style: normal; font-variant-ligatures=
: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: norm=
al; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; =
white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-widt=
h: 0px; background-color: #ffffff; text-decoration-thickness: initial; text=
-decoration-style: initial; text-decoration-color: initial; display: inline=
 !important; float: none;"><span style=3D"color: #000000; font-family: Cali=
bri, sans-serif; font-size: 14.6667px; font-style: normal; font-variant-lig=
atures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing=
: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: =
none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-strok=
e-width: 0px; background-color: #ffffff; text-decoration-thickness: initial=
; text-decoration-style: initial; text-decoration-color: initial; display: =
inline !important; float: none;" data-mce-style=3D"color: #000000; font-fam=
ily: Calibri, sans-serif; font-size: 14.6667px; font-style: normal; font-va=
riant-ligatures: normal; font-variant-caps: normal; font-weight: 400; lette=
r-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-tr=
ansform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-t=
ext-stroke-width: 0px; background-color: #ffffff; text-decoration-thickness=
: initial; text-decoration-style: initial; text-decoration-color: initial; =
display: inline !important; float: none;"><span style=3D"color: #000000; fo=
nt-family: Calibri, sans-serif; font-size: 14.6667px; font-style: normal; f=
ont-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400;=
 letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; t=
ext-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -we=
bkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-thi=
ckness: initial; text-decoration-style: initial; text-decoration-color: ini=
tial; display: inline !important; float: none;" data-mce-style=3D"color: #0=
00000; font-family: Calibri, sans-serif; font-size: 14.6667px; font-style: =
normal; font-variant-ligatures: normal; font-variant-caps: normal; font-wei=
ght: 400; letter-spacing: normal; orphans: 2; text-align: start; text-inden=
t: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing:=
 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decor=
ation-thickness: initial; text-decoration-style: initial; text-decoration-c=
olor: initial; display: inline !important; float: none;">&gt;th&lt;superscr=
ipt<span>&nbsp;</span><span style=3D"color: #000000; font-family: Calibri, =
sans-serif; font-size: 14.6667px; font-style: normal; font-variant-ligature=
s: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: nor=
mal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none;=
 white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-wid=
th: 0px; text-decoration-thickness: initial; text-decoration-style: initial=
; text-decoration-color: initial;" data-mce-style=3D"color: #000000; font-f=
amily: Calibri, sans-serif; font-size: 14.6667px; font-style: normal; font-=
variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; let=
ter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-=
transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit=
-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoratio=
n-style: initial; text-decoration-color: initial;">&nbsp;</span>type=3D"e" =
id=3D"ID02"</span></span></span><span style=3D"color: #000000; font-family:=
 Calibri, sans-serif; font-size: 14.6667px; font-style: normal; font-varian=
t-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-sp=
acing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transf=
orm: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-=
stroke-width: 0px; background-color: #ffffff; text-decoration-thickness: in=
itial; text-decoration-style: initial; text-decoration-color: initial; disp=
lay: inline !important; float: none;" data-mce-style=3D"color: #000000; fon=
t-family: Calibri, sans-serif; font-size: 14.6667px; font-style: normal; fo=
nt-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; =
letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; te=
xt-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -web=
kit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-thic=
kness: initial; text-decoration-style: initial; text-decoration-color: init=
ial; display: inline !important; float: none;"><span style=3D"color: #00000=
0; font-family: Calibri, sans-serif; font-size: 14.6667px; font-style: norm=
al; font-variant-ligatures: normal; font-variant-caps: normal; font-weight:=
 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0=
px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px=
; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoratio=
n-thickness: initial; text-decoration-style: initial; text-decoration-color=
: initial; display: inline !important; float: none;" data-mce-style=3D"colo=
r: #000000; font-family: Calibri, sans-serif; font-size: 14.6667px; font-st=
yle: normal; font-variant-ligatures: normal; font-variant-caps: normal; fon=
t-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-=
indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spa=
cing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-=
decoration-thickness: initial; text-decoration-style: initial; text-decorat=
ion-color: initial; display: inline !important; float: none;">&gt;&lt;var&n=
bsp;<!--StartFragment--><span>&nbsp;</span>type=3D"r" id=3D"ID01"/&gt;<!--E=
ndFragment--></span></span><span style=3D"color: #000000; font-family: Cali=
bri, sans-serif; font-size: 14.6667px; font-style: normal; font-variant-lig=
atures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing=
: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: =
none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-strok=
e-width: 0px; background-color: #ffffff; text-decoration-thickness: initial=
; text-decoration-style: initial; text-decoration-color: initial; display: =
inline !important; float: none;" data-mce-style=3D"color: #000000; font-fam=
ily: Calibri, sans-serif; font-size: 14.6667px; font-style: normal; font-va=
riant-ligatures: normal; font-variant-caps: normal; font-weight: 400; lette=
r-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-tr=
ansform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-t=
ext-stroke-width: 0px; background-color: #ffffff; text-decoration-thickness=
: initial; text-decoration-style: initial; text-decoration-color: initial; =
display: inline !important; float: none;"></span><!--EndFragment--><div sty=
le=3D"clear: both;" data-mce-style=3D"clear: both;"><br></div><div style=3D=
"clear: both;" data-mce-style=3D"clear: both;">if so all your characters ar=
e siblings, so can do a line breaking algorithm, preserving the empty eleme=
nts</div><div style=3D"clear: both;" data-mce-style=3D"clear: both;">after =
that you simply reconstruct the elements</div></div></div><div><br></div><d=
iv data-marker=3D"__SIG_PRE__"><div>Met vriendelijke groeten,<br>Best regar=
ds,<br><br>Geert Bormans<br></div></div><div><br><span id=3D"zwchr" data-ma=
rker=3D"__DIVIDER__">----- Op 14 apr 2021 om 11:46 schreef Trevor Nicholls =
[email protected] &lt;[email protected]&gt;:<=
br></span><br><style>/*<![CDATA[*/p.MsoNormal, li.MsoNormal, div.MsoNormal {
	margin: 0.0cm;
	font-size: 11.0pt;
	font-family: Calibri , sans-serif;
}
span.EmailStyle17 {
	font-family: Calibri , sans-serif;
	color: windowtext;
}
*.MsoChpDefault {
	font-family: Calibri , sans-serif;
}
div.WordSection1 {
	page: WordSection1;
}
/*]]>*/</style></div><div data-marker=3D"__QUOTED_TEXT__"><div class=3D"Wor=
dSection1"><p class=3D"MsoNormal">NB currently XSL 2.0</p><p class=3D"MsoNo=
rmal">&nbsp;</p><p class=3D"MsoNormal">I'm struggling with what I thought w=
ould be a simple enough problem:</p><p class=3D"MsoNormal">&nbsp;</p><p cla=
ss=3D"MsoNormal">given content like this</p><p class=3D"MsoNormal">&nbsp;</=
p><p class=3D"MsoNormal">"&lt;code&gt;Mixed content, mainly text but with s=
ome text such as &lt;var&gt;variable names&lt;/var&gt; wrapped in elements,=
 sometimes nested like a reference to the &lt;var&gt;n&lt;superscript&gt;th=
&lt;/superscript&gt;&lt;/var&gt; occurrence.&lt;/code&gt;"</p><p class=3D"M=
soNormal">&nbsp;</p><p class=3D"MsoNormal">and a constraint that code shoul=
d be rendered within a fixed width box, I need to come up with a template w=
hich will process the &lt;code&gt; element and transform it into its word-w=
rapped equivalent.</p><p class=3D"MsoNormal">&nbsp;</p><p class=3D"MsoNorma=
l">I don't need to concern myself with character sizes or styles; the outpu=
t of this transformation will always be rendered in a fixed-width font.</p>=
<p class=3D"MsoNormal">&nbsp;</p><p class=3D"MsoNormal">I can write somethi=
ng which works fine if a &lt;code&gt; element is simple text - but the requ=
irement is for this to work with mixed content too. In the above example, i=
f the constraint is that the line must wrap at or before 64 characters, the=
 first break comes in the middle of the first &lt;var&gt;.</p><p class=3D"M=
soNormal">&nbsp;</p><p class=3D"MsoNormal">Assuming that the &lt;code&gt; e=
xample above is the current element, what I am trying to write is a templat=
e</p><p class=3D"MsoNormal">&nbsp;</p><p class=3D"MsoNormal">&lt;xsl:templa=
te name=3D"wordwrap"&gt;</p><p class=3D"MsoNormal">&nbsp; &lt;xsl:param nam=
e=3D"input" select=3D"." /&gt;</p><p class=3D"MsoNormal">&nbsp; &lt;xsl:par=
am name=3D"linelen" select=3D"64" /&gt;</p><p class=3D"MsoNormal">=E2=80=A6=
</p><p class=3D"MsoNormal">&lt;/xsl:template&gt;</p><p class=3D"MsoNormal">=
&nbsp;</p><p class=3D"MsoNormal">that will output</p><p class=3D"MsoNormal"=
>&nbsp;</p><p class=3D"MsoNormal">"Mixed content, mainly text but with some=
 text such as &lt;var&gt;variable&lt;/var&gt;&lt;wordwrap/&gt;</p><p class=
=3D"MsoNormal">&lt;var&gt;names&lt;/var&gt; wrapped in elements, sometimes =
nexted like a reference to&lt;wordwrap/&gt;</p><p class=3D"MsoNormal">the &=
lt;var&gt;n&lt;superscript&gt;th&lt;/superscript&gt;&lt;/var&gt; occurrence=
."</p><p class=3D"MsoNormal">&nbsp;</p><p class=3D"MsoNormal">Can anyone of=
fer me some pointers as to how I should implement this?</p><p class=3D"MsoN=
ormal">&nbsp;</p><p class=3D"MsoNormal">Cheers</p><p class=3D"MsoNormal">T<=
/p></div>
<div>
<div style=3D"border-top:1px solid black;background-color:#dddddd;color:#88=
8888;font-size:smaller;padding:5px;text-align:center;font-family:'arial' , =
'verdana' , 'arial' , sans-serif;margin-top:1em;margin:auto">
<a href=3D"http://www.mulberrytech.com/xsl/xsl-list" target=3D"_blank" rel=
=3D"nofollow noopener noreferrer">
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/554170" target=3D"_blank" rel=3D"nofollow noopener noreferrer">EasyUnsubs=
cribe</a>
(<a style=3D"color:blue" href=3D"" target=3D"_blank" rel=3D"nofollow noopen=
er noreferrer">by email</a>)
</div>
</div>
</div><br></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>

--=_a6fb6b41-f7f4-41ad-8866-57cf9bae99b7--