Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: Replace hithighlight tags >Thread Next - Re: Replace hithighlight tags Re: Replace hithighlight tagsTo: NULL Date: 10/8/2005 3:57:00 AM Hi Ixa,
Thanks for the suggestion.
But I think: <xsl:template match="searchhit">
won't work because of <searchhit> and </searchhit> being CDATA within
the fulltext element.
I think I need some sort of replacement template to replace the
<searchhit> tags.
I've already been experimenting with it, but didn't reach the goal yet.
I can replace the opening <searchhit> tags now, but when I store the
result of that replacement in a variable and then use that variable as
the input of the replacement of the closing tags it won't work anymore.
Here's what I tried:
========================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="/result/document/fulltext">
<xsl:variable name="openTags">
<xsl:call-template name="replace">
<xsl:with-param name="text" select="." />
<xsl:with-param name="from" select="'<searchhit>'"/>
<xsl:with-param name="with" select="'<span
style="background: red;">'"/>
</xsl:call-template>
</xsl:variable>
<xsl:call-template name="replace">
<xsl:with-param name="text"><xsl:copy-of
select="$openTags"/></xsl:with-param>
<xsl:with-param name="from" select="'</searchhit>'"/>
<xsl:with-param name="with" select="'</span>'"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="replace">
<xsl:param name="text"/>
<xsl:param name="from"/>
<xsl:param name="with"/>
<xsl:choose>
<xsl:when test="$from and contains($text,$from)">
<xsl:value-of select="substring-before($text,$from)"/>
<xsl:value-of disable-output-escaping="yes" select="$with"/>
<xsl:call-template name="replace">
<xsl:with-param name="text"
select="substring-after($text,$from)"/>
<xsl:with-param name="from" select="$from"/>
<xsl:with-param name="with" select="$with"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
========================================================
The output of this is that the <searchhit> tags get replaced by
<span style="background: red;"> and the closing </searchhit> tags get
replaced by: </searchhit>
So in the output I get: <span style="background:
red;">mixing</searchhit>
However, when I leave out the second call to the replace template and
just do this:
======================================================
<xsl:variable name="openTags">
<xsl:call-template name="replace">
<xsl:with-param name="text" select="." />
<xsl:with-param name="from" select="'<searchhit>'"/>
<xsl:with-param name="with" select="'<span
style="background: red;">'"/>
</xsl:call-template>
</xsl:variable>
<xsl:copy-of select="$openTags"/>
======================================================
The <span background: "red";> tags are being parsed by the browser and
everything after it gets a red background.
Any ideas?
Thanks.
Kind regards,
Peter.
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
