Re: [xsl] Transform symbol to element

Subject: Re: [xsl] Transform symbol to element
From: Syd Bauman <Syd_Bauman@xxxxxxxxx>
Date: Wed, 11 Nov 2009 07:30:16 -0500
I'm not sure that regular expression is exactly what Martin intended,
or if mail gateways have mucked it enough that I couldn't tell
anyway. In any case, if you never have quoted phrases nested inside
quoted phrases, it makes little or no difference whether you use left
or right quotation marks in the negated 2nd group. But if you might
have nestings of pairs of quotation marks you want to catch properly
(even if not completely), you probably need to have both in there.
I.e., using 'L' for left and 'R' for right:
    (L)([^LR]*)(R)

This works (or at least, does what I expect :-) in the single-match
case (i.e., matching either single or double). But when matches for
both single and double are combined using a pipe character, it fails
to handle the second case, I haven't figured out why. I.e.
    (L)([^LR]*)(R)|(l)([^lr]*)(r)
catches quotations surrounded by 'L' and 'R', but fails to catch the
case of quotations surrounded by 'l' and 'r'. (Using Saxon-HE
9.2.0.3J from Saxonica).


But, perhaps more importantly, keep in mind that Martin's sample code
drops the encoding of child elements. E.g.
       "A Detailed Analysis of Allusions to Markup Technology
        in Homer's <title>Iliad</title>"
would become
       <quote>A detailed ... Homer's Iliad</quote>
losing the <title> tags, I think.


> With XSLT 2.0 you can try it as follows:
>    <xsl:template match="p">
>      <para>
>        <xsl:analyze-string select="." regex="()([^]*)()|()([^]*)()">
>          <xsl:matching-substring>
>            <quote open="{regex-group(1)}" close="{regex-group(3)}">
>              <xsl:value-of select="regex-group(2)"/>
>            </quote>
>          </xsl:matching-substring>
>          <xsl:non-matching-substring>
>            <xsl:value-of select="."/>
>          </xsl:non-matching-substring>
>        </xsl:analyze-string>
>      </para>
>    </xsl:template>

Current Thread