The only change I would make to Andrew's code is to use templates:
<xsl:template match=3D"*[key('acr', ., $acronyms)]">
<xsl:copy>
<xsl:copy-of select=3D"@*">
<acronym><xsl:value-of select=3D"."/></acronym>
</xsl:copy>
</xsl:template>
<xsl:template match=3D"*">
<xsl:copy>
<xsl:copy-of select=3D"@*">
<xsl:value-of select=3D"."/>
</xsl:copy>
</xsl:template>=20
However, I'm not quite sure this is what you want. In your code
<p>IBMICL</p> would expand to
<p><acronym>IBM</acronym><acronym>ICL</acronym></p> if IBM and ICL are =
both
acronyms. Is this what you want? I would have thought that if you are
looking for acronyms anywhere in the text, then you need to do some kind =
of
tokenization of the text first, and then process each token to see if it =
is
an acronym. It might well be appropriate to use a regex for the
tokenization, but testing whether the token is an acronym is still best =
done
using a key.
Michael Kay
> -----Original Message-----
> From: saxon-help-admin@...
> [mailto:saxon-help-admin@...] On Behalf Of=20
> andrew welch
> Sent: 14 March 2006 15:51
> To: saxon-help@...
> Subject: Re: [saxon] SXLM0001: Too many nested=20
> apply-templates calls. saxon 8
>=20
> On 3/14/06, Dave Pawson <dave.pawson@...> wrote:
> > On 14/03/06, Michael Kay <mike@...> wrote:
> > >
> > > >
> > > > I can't see how keys can be used in place of a regex Michael?
> > >
> > > You need to show me cut-down samples of the input and=20
> output files. So far I
> > > haven't seen the detail of the problem, only an outline=20
> description.
> >
> > XSL
> >
> > <!-- External acronyms -->
> > <xsl:variable name=3D"acronyms"
> > select=3D"document('acronyms.xml')/acronyms" />
> >
> > <xsl:variable name=3D"acronym-regex" as=3D"xs:string"
> > select=3D"string-join($acronyms/acr, '|')" />
> >
> >
> > <xsl:template match=3D"p|pre" priority=3D"0.6">
> >
> > <xsl:copy>
> > <xsl:copy-of select=3D"@*"/>
> > <xsl:analyze-string select=3D"." regex=3D"{$acronym-regex}">
> > <xsl:matching-substring>
> > <acronym><xsl:value-of select=3D"." /></acronym>
> > </xsl:matching-substring>
> > <xsl:non-matching-substring>
> > <xsl:value-of select=3D"." />
> > </xsl:non-matching-substring>
> > </xsl:analyze-string>
> > </xsl:copy>
> > </xsl:template>
>=20
> I'll jump in too if that's ok...
>=20
> I would create a key:
>=20
> <xsl:key name=3D"acronyms" match=3D"acr" use=3D"."/>
>=20
> and then check if the acronym exists by seeing if its in the key:
>=20
> <xsl:choose>
> <xsl:when test=3D"key('acronyms', ., $acronyms)">
> <acronym>....
> </xsl:when>
> <xsl:otherwise>
> <xsl:value-of select=3D"."/>
>=20
> cheers
> andrew
>=20
>=20
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking=20
> scripting language
> that extends applications into web and mobile media. Attend=20
> the live webcast
> and join the prime developer group breaking into this new=20
> coding territory!
> http://sel.as-us.falkag.net/sel?cmd=3Dk&kid=110944&bid$1720&dat=121642
> _______________________________________________
> saxon-help mailing list
> saxon-help@...
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>=20
|