Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSL like or fuzzy search?

Tags:

foreach

xslt

Is there any XSL equivalent of the SQL like or a fuzzy search?

For example:

<xsl:for-each select="foo[foo_type like '%1%']">
like image 459
Morgan Dowell Avatar asked Aug 23 '11 21:08

Morgan Dowell


2 Answers

Use ( in the select attribute) the standard XPath function contains() as in following XPath expression:

foo[contains(foo_type, '1')]

Depending on the concrete case, other standard XPath functions, as listed below, may also be useful:

  • starts-with()

  • ends-with()

  • substring()

  • substring-before()

  • substring-after()

  • string()

  • string-length()

  • concat()

  • translate()

  • normalize-space()

  • matches()

  • replace()

  • tokenize()

Do note that ends-with(), matches(), tokenize() and replace() are available only in XPath 2.0.

One can use the following XPath 1.0 expression for the same purpose as the XPath 2.0 function ends-with():

  substring($s, string-length($s) - string-length($target) +1)
=
  $target

is equivalent to:

ends-with($s, $target)
like image 96
Dimitre Novatchev Avatar answered Nov 15 '22 09:11

Dimitre Novatchev


Not exactly, but you have a lot of string functions, as contains, starts-with, etc. You can see MS' documentation on these functions here:

http://msdn.microsoft.com/en-us/library/ms256195.aspx

Your particular select would be something like:

<xsl:for-each select="*[contains(name(),'1')]">
like image 25
Erik A. Brandstadmoen Avatar answered Nov 15 '22 09:11

Erik A. Brandstadmoen