Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: Cindy Girard <clm6u@------------>
To:
Date: 8/2/2006 5:29:00 PM
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>


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