I want to write a stylesheet that highlights a keyword in a text.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:param name="keyword">keyword</xsl:param>
<html>
<body>
<xsl:for-each select="element()">
<xsl:variable name="elValue" select="."/>
<xsl:analyze-string select="upper-case(.)" regex="{upper-case($keyword)}*">
<xsl:matching-substring>
<i>
<xsl:value-of select="."/>
</i>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
I have used regular expressions.
My problem: the whole html-output is now in upper-case. I have tried to use the variable elValue to save the original value, but that does not work. The variable seems to append the new value in each loop (and does not only contain the new value).
Is there a way to output the original format of the elements (no upper case)?
Thanks in advance,
You might simply want to use an
iflag on http://www.w3.org/TR/xslt20/#analyze-string i.e.