RE: [xsl] xsl search engine

Subject: RE: [xsl] xsl search engine
From: "Ricaud Matthieu" <matthieu.ricaud@xxxxxxx>
Date: Thu, 18 Mar 2004 12:01:23 +0100
Hi Jarno !

Thanks for the advice about the multi occurence highlighting ...
It works fine if the user query contains  more than one word but for exactly
one word, it highlight only the fisrt occurence in the result. I just had to
change another line in the 2nd <when> :

<xsl:choose>
	<xsl:when test="contains($text, ' ')">
		...
		...

      <xsl:when test="$text">
        <xsl:choose>
          <xsl:when test="contains($label, $text)">
            <xsl:value-of select="substring-before($label, $text)"/>
            <em>
              <xsl:value-of select="$text"/>
            </em>
           <! instead of : <xsl:value-of select="substring-after($label,
$text)"/> here I go : -->
			<xsl:call-template name="highlight">
				<xsl:with-param name="label" select="substring-after($label, $text)"/>
				<xsl:with-param name="text" select="$text"/>
			</xsl:call-template>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$label"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>

The engine is better and better :) About accents and case insensitive I did
translate everything to low case without accent, it works good exept that
the result is also displayed without accents and Low char...
But anyway the engine is great and I' m really satisfied, thanks again for
your p^recious help !
Cheers,
Matthieu.




-----Message d'origine-----
De : owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]De la part de
Jarno.Elovirta@xxxxxxxxx
Envoyé : mercredi 17 mars 2004 08:14
À : xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Objet : RE: [xsl] xsl search engine


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


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


Current Thread