Here is the xml:
<?xml version="1.0" encoding="UTF-8"?>
<file>
<text>
<p>
<sentence>I bought kiwi at the grocery store.</sentence>
<sentence>I also bought bananas at the store.</sentence>
<sentence>Then, I bought a basket at another store.</sentence>
</p>
<p>
<sentence>You bought kiwi at the grocery store.</sentence>
<sentence>You also bought bananas at the store.</sentence>
<sentence>Then, You bought a basket at another store.</sentence>
</p>
</text>
</file>
And here is the XSLT:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="sentence">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="file/text/p/sentence[contains(.,$search)]"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
I need to highlight the $search
word in the results like this when $search="kiwi"
:
I bought <mark>
kiwi</mark>
at the grocery store.
You bought <mark>
kiwi</mark>
at the grocery store.
Please help!
To highlight all occurrences of the search string, change this:
to: