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

Highlighting words/phrases

Subject: Highlighting words/phrases
From: yguaba@xxxxxxxxxxxx
Date: Thu, 27 Jul 2006 18:27:13 -0300
css highlight words
Dear all,

I am using XSLT to output search results. The source XML files can be 
very roughly exemplified thus:

		<keyword>another search term</keyword>
	<document number="x">
		<contents>sample text</contents>
	<document number="y">
		<contents>another sample</contents>

Basically, I want to be able to "highlight" the key words and phrases 
("keyword" elements) by enclosing each of them within, say, a "span" 
tag with a certain "class" attribute (in order to style these bits 
via CSS).

My first idea was to use some kind of a search/replace routine, like 

<xsl:template name="highlight">
	<xsl:param name="input"/>
	<xsl:param name="search-string"/>
	<!-- CSS class -->
	<xsl:param name="class-name"/>
		<xsl:when test="$search-string and contains($input, $search-
			<xsl:value-of select="substring-before($input, $search-string)"/>
				<span class="{$class-name}">
					<xsl:value-of select="$search-string"/>
				<xsl:call-template name="search-and-replace">
					<xsl:with-param name="input" select="substring-after($input, 
					<xsl:with-param name="search-string" select="$search-string"/>
					<xsl:with-param name="class-name" select="$class-name"/>
			<xsl:value-of select="$input"/>

The problem is that this would only highlight the first key word or 
phrase. But I would need to iterate through all the key words using 
xsl:for-each and highlight them all, which would of course not work 
with the above template.

Any suggestions or links to possible solutions would be appreciated.



Novidade no Yahoo! Mail: receba alertas de novas mensagens no seu celular. Registre seu aparelho agora! 

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

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.
First Name
Last Name
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-2013 All Rights Reserved.