[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Re[2]: Highlighting words/phrases

Subject: Re: Re[2]: Highlighting words/phrases
From: "Alexander Johannesen" <alexander.johannesen@xxxxxxxxx>
Date: Thu, 3 Aug 2006 11:02:51 +1000
xsl highlight
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/ __________________________________________________

Current Thread

Back To School Sale!

Save 30% off all Stylus Studio 2008 Products when you purchase from our Online Shop.

Offer ends August 31, 2008.

Coupon Code
TRTY-C4JV-OFF

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.