RE: [xsl] xsl search engine

Subject: RE: [xsl] xsl search engine
From: Jarno.Elovirta@xxxxxxxxx
Date: Wed, 17 Mar 2004 09:13:52 +0200
Hi,

> When I have the time I'll try to perfect it, I didn't manage 
> to get out of
> the problem of Case and accents :
> it's harder then just add translate($text, 'ABCDEFG...éèê', 
> 'abcdef...eee')
> on every contains() and most of all it's hard to get the 
> result with the
> original case at the end.

Doing case-insensitive operations in XSLT isn't easy. Anyhow, you can put the uppercase and lowercase strings into variables $u and $l, that will make the code a tad more readable.
 
> Other thing is that the @label contains twice the searched 
> expression then
> it will will be display once (that was a last problem) BUT it 
> will highlight
> only the first occurence...

Oh yeah. Just make the template a bit less greedy

  <xsl:template name="highlight">
    <xsl:param name="label" select="@label"/>
    <xsl:param name="text" select="normalize-space($string)"/>
    <xsl:choose>
      <xsl:when test="contains($text, ' ')">
        <xsl:variable name="current" select="substring-before($text, ' ')"/>
        <xsl:choose>
          <xsl:when test="contains($label, $current)">
            <xsl:call-template name="highlight">
              <xsl:with-param name="label"  select="substring-before($label, $current)"/>
              <xsl:with-param name="text" select="$text"/> <!-- change this -->
            </xsl:call-template>
            <em>
              <xsl:value-of select="$current"/>
            </em>
            <xsl:call-template name="highlight">
              <xsl:with-param name="label"  select="substring-after($label, $current)"/>
              <xsl:with-param name="text" select="$text"/> <!-- change this -->
            </xsl:call-template>
          </xsl:when>

i.e. don't move on to the next token once a match is found, but rather continue with that same token until it's not found. The rest of the template is the same.

Cheers,

Jarno - Tactical Sekt: Xfixiation (Hellfire mix by [:SITD:] )

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread