Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Re[2]: [xsl] Highlighting words/phrases

From: "Alexander Johannesen" <alexander.johannesen@--------->
To:
Date: 8/3/2006 1:03:00 AM
Hi all,



On 8/3/06, Cindy Girard <clm6u@xxxxxxxxxxxx> wrote:
I'm also trying to highlight a specific word or phrase in the text of
a document.

I've got a word highlighter (it only bolds stuff, but you can put in
whatever you need) that is case insensitive and unicode compatible
(using str:to-lower function from the xsltsl project
[http://xsltsl.org] : replace this with your own lowercaser
transformation if you like).

Input is $text (your full text) and $what (what to highlight ; terms,
words, etc.) ;

	<xsl:template name="highlighter">
		<xsl:param name="text"/>
		<xsl:param name="what"/>
		<xsl:variable name="test-text">
			<xsl:call-template name="str:to-lower">
				<xsl:with-param name="text" select="$text" />
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="test-what">
			<xsl:call-template name="str:to-lower">
				<xsl:with-param name="text" 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"/>
				<b><xsl:value-of select="$what"/></b>
				<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"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>


Regards,



Alex
--
"Ultimately, all things are known because you want to believe you know."
                                                        - Frank Herbert
__ http://shelter.nu/ __________________________________________________


transparent
Print
Mail
Digg
delicious
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