RE: [xsl] RE: XPath expression to perform 'keyword' query

Subject: RE: [xsl] RE: XPath expression to perform 'keyword' query
From: "Lars Huttar" <lars_huttar@xxxxxxx>
Date: Sat, 18 Oct 2003 13:13:29 -0500
> I still have one problem.  I can't get it to search on more 
> than one keyword. 
> I think this is because I'm using the contains() function like this:
> contains({element content}, $keywords)
> Any ideas?

You could do
  contains({element content}, $keyword1) and contains({element content}, $keyword2)

but of course that would only work if the number of keywords was fixed in advance

Otherwise you'd probably have to define a recursive template to parse

Something like:  (untested)

 <xsl:template name="contains-keywords">
   <xsl:param name="str" select="''" />
   <xsl:param name="keywords" select="''" />
   <!-- Return '1' if the given string contains all keywords
     (space-separated strings); otherwise '0'. -->
     <xsl:when test="$str = ''">1</xsl:when>
       <xsl:variable name="first-keyword" select="substring-before($keywords, ' ')" />
         <xsl:when test="contains($str, $first-keyword)">
           <xsl:call-template name="contains-keywords">
		   <xsl:with-param name="str" select="$str" />
		   <xsl:with-param name="keywords" select="substring-after($keywords, ' ')" />


 XSL-List info and archive:

Current Thread