...">

Xsl like or fuzzy search?

Is there any xsl equivalent sql, for example or fuzzy search ?

eg:

<xsl:for-each select="foo[foo_type like '%1%']"> 
+6
source share
3 answers

Not really, but you have a lot of string functions like contains , starts-with , etc. Here you can see the MS documentation for these functions:

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

Your specific choice will look something like this:

 <xsl:for-each select="*[contains(name(),'1')]"> 
+3
source

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

 foo[contains(foo_type, '1')] 

Other standard XPath functions, listed below, may also be useful, as appropriate. :

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

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

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

is equivalent to:

 ends-with($s, $target) 
+3
source

In XSLT 2.0 use

 <xsl:for-each select="foo[matches(foo_type, '1')]"> 

Unlike SQL, which has a fairly primitive and unorthodox syntax for templates, XSLT uses regular expressions that are very close to the syntax used in Perl and most other modern regex dialects.

+1
source

Source: https://habr.com/ru/post/895709/


All Articles