This could be much easier to solve with XSLT 2.0.
Below is a 2.0 stylesheet, which does the similar task,
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/doc">
<xsl:apply-templates select="p" />
</xsl:template>
<xsl:template match="p">
<p>
<xsl:analyze-string
select="."
regex="{string-join(../keywords/keyword,'|')}">
<xsl:matching-substring>
<em><xsl:value-of select="." /></em>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="." />
</xsl:non-matching-substring>
</xsl:analyze-string>
</p>
</xsl:template>
</xsl:stylesheet>
The input XML is,
<doc>
<keywords>
<keyword>transformation</keyword>
<keyword>XSLT</keyword>
<keyword>source tree</keyword>
<keyword>result tree</keyword>
<keyword>template</keyword>
</keywords>
<p>
A transformation expressed in XSLT describes rules for
transforming a source tree into
a result tree. The transformation is achieved by associating
patterns with templates. A
pattern is matched against elements in the source tree. A template
is instantiated to
create part of the result tree. The result tree is separate from
the source tree. The
structure of the result tree can be completely different from the
structure of the source
tree. In constructing the result tree, elements from the source
tree can be filtered and
reordered, and arbitrary structure can be added.
</p>
</doc>
The output as specified in the problem statement is produced ...
On Wed, Aug 20, 2008 at 11:16 PM, M C <mcundiff11(_at_)yahoo(_dot_)com> wrote:
I am trying the stylesheet by Jeni Tennison at:
http://jenitennison.com/xslt/utilities/markup.xsl
This stylesheet is exactly what I need (i.e. to insert markup around a list
of specified phrases that occur in the text nodes of an existing xml doc).
I am looking at the example page at:
http://jenitennison.com/xslt/utilities/markup-example.xml
and am wondering why (in the output) the final occurrence of the phrase
"result tree" does not get marked up. Can anyone explain? Here is output
(notice that the final occurrence of "result tree" is not wrapped in <em> tag
as are the others.
Thanks,
Morgan
-------------------------------
<p>
A <em>transformation</em> expressed in <em>XSLT</em> describes rules for
transforming a <em>source tree</em> into
a <em>result tree</em>. The <em>transformation</em> is achieved by
associating patterns with templates. A
pattern is matched against elements in the <em>source tree</em>. A
<em>template</em> is instantiated to
create part of the <em>result tree</em>. The <em>result tree</em> is
separate from the <em>source tree</em>. The
structure of the <em>result tree</em> can be completely different from the
structure of the source
tree. In constructing the result tree, elements from the <em>source
tree</em> can be filtered and
reordered, and arbitrary structure can be added.
</p>
--
Regards,
Mukul Gandhi
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--