hello,
Ive come across a highlight function that i was able to add to a search feature i have on a page. however the current method it uses will wrap text that is found even inside of html so its making the tags no longer work. has anyone dealt with this type of thing before?
here's the highlighter template
example of problem
$text = <a href=" steps to walkthrough</a>
$what = walk
output=<a href=" style...>walk</font>throughs.com">Simple steps to <font style...>walk</font>through</a>
Id appreciate any insight on this. i thought that perhaps i could examine for an unclosed < in before variable and unopened > in after but im not sure what the best way to do this would be
Thanks in advance
MCP, .Net Solutions Development <%_%>
Ive come across a highlight function that i was able to add to a search feature i have on a page. however the current method it uses will wrap text that is found even inside of html so its making the tags no longer work. has anyone dealt with this type of thing before?
here's the highlighter template
example of problem
$text = <a href=" steps to walkthrough</a>
$what = walk
output=<a href=" style...>walk</font>throughs.com">Simple steps to <font style...>walk</font>through</a>
Code:
<xsl:template name="highlighter">
<xsl:param name="text"/>
<xsl:param name="what"/>
<xsl:variable name="test-text">
<xsl:call-template name="lower">
<xsl:with-param name="tolower" select="$text" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="test-what">
<xsl:call-template name="lower">
<xsl:with-param name="tolower" select="$what" />
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains($test-text, $test-what)">
<xsl:variable name="before" select="substring-before($test-text,$test-what)"/>
<xsl:variable name="after" select="substring-after($test-text,$test-what)"/>
<xsl:variable name="real-before" select="substring($text, 1,string-length($before))"/>
<xsl:variable name="real-after" select="substring($text,string-length($before) + string-length($what) + 1)"/>
<xsl:value-of select="$real-before" disable-output-escaping="yes"/>
<font style="background-color:#66FF66"><xsl:value-of select="$what" disable-output-escaping="yes"/></font>
<xsl:call-template name="highlighter">
<xsl:with-param name="text" select="$real-after"/>
<xsl:with-param name="what" select="$what"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text" disable-output-escaping="yes"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Id appreciate any insight on this. i thought that perhaps i could examine for an unclosed < in before variable and unopened > in after but im not sure what the best way to do this would be
Thanks in advance
MCP, .Net Solutions Development <%_%>