Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Replace hithighlight tags

From: "Peter van Schie" <vanschie.peter@-----.--->
To: 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="'&lt;searchhit&gt;'"/>
		    <xsl:with-param name="with" select="'&lt;span
style=&#34;background: red&#59;&#34;&gt;'"/>
		</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="'&lt;&#47;searchhit&gt;'"/>
		    <xsl:with-param name="with" select="'&lt;&#47;span&gt;'"/>
	</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: &lt;/searchhit&gt;
So in the output I get: <span style="background:
red;">mixing&lt;/searchhit&gt;

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="'&lt;searchhit&gt;'"/>
		    <xsl:with-param name="with" select="'&lt;span
style=&#34;background: red&#59;&#34;&gt;'"/>
		</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.



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent