[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] search against index


Subject: Re: [xsl] search against index
From: Américo Albuquerque <melinor@xxxxxxx>
Date: Thu, 07 Aug 2003 15:58:51 +0100 (WEST)

Hi.

Citando bryan <bry@xxxxxxxxxx>:

} 
} I have a parameter $string
} 
} And I do <xsl:apply-templates select="index[contains(@value,$string)]"/>
} 
} This works great, but I want to do a search with string + string, in
} other words given limitations of xslt, a search with multiple contains.
} 
} So for example:
} <list>
} <index value="a string of values here">
} result
} </index>
} <index value="another string here">
} result2
} </index>
} </list>
} 
} 
} if $string = "another"
} 
} this returns the second index node, if $string  = "another + here"
} 
} then it still returns the second index node, if $string = "string +
} here" it returns both nodes.
} 
(...)

Try this:
  <xsl:param name="string" select="''"/>
  <xsl:template match="list">
    <result>
      <xsl:call-template name="search">
        <xsl:with-param name="nodes" select="index"/>
        <xsl:with-param name="string" select="$string"/>
      </xsl:call-template>
    </result>
  </xsl:template>

  <xsl:template name="search">
    <xsl:param name="nodes" select="/.."/>
    <xsl:param name="string" select="''"/>
    <xsl:choose>
      <xsl:when test="contains($string,'+')">
        <xsl:call-template name="search">
          <xsl:with-param name="nodes" select="$nodes[contains(@value,normalize-space
(substring-before($string,'+')))]"/>
          <xsl:with-param name="string" select="normalize-space(substring-after
($string,'+'))"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:copy-of select="$nodes[contains(@value,$string)]"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

Hope this helps you.

Regards,
Americo Albuquerque
___________________________________________________________________

O SAPO já está livre de vírus com a Panda Software, fique você também!
Clique em: http://antivirus.sapo.pt


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



Current Thread
Keywords