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

Re[2]: Highlighting words/phrases

Subject: Re[2]: Highlighting words/phrases
From: Cindy Girard <clm6u@xxxxxxxxxxxx>
Date: Wed, 2 Aug 2006 13:28:38 -0400
cindy girard
Hi.

I'm also trying to highlight a specific word or phrase in the text of
a document. However, the input is coming from the command line. Erik's
example helped me alot, but I'm having a little difficulty with the
recursion. Within the same element, I only get the first two instances
of the word highlighted.

The code is below. Any help would be appreciated.

Thanks,
Cindy

Cindy Girard
clm6u@xxxxxxxxxxxx

-----------------------

<xsl:template name="highlight">
  <xsl:param name="keyword" select="$keyword"/>
  <xsl:param name="input" select="."/>
  <xsl:param name="search-string" select="$keyword"/>
  <xsl:choose>
    <xsl:when test="$search-string and contains($input, $search-string)">
      <xsl:value-of select="substring-before($input, $search-string)"/>
      <hi rend="highlight">
        <xsl:value-of select="$search-string"/>
      </hi>
      <xsl:call-template name="highlight">
        <xsl:with-param name="input" select="substring-after($input, $search-string)"/>
        <xsl:with-param name="search-string" select="$search-string"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:apply-templates/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="p">
  <xsl:copy>
    <xsl:apply-templates
     select="*|@*|comment()|processing-instruction()"/>
    <xsl:call-template name="highlight" select="p"/>
  </xsl:copy>
</xsl:template>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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