Find the number of occurences of a substring in a string in xslt

前端 未结 2 1182
遥遥无期
遥遥无期 2020-12-11 11:22

I am writing a script to find the number of occurrences of a substring in a string in XSLT. It\'s taking too much time when I want to traverse it in more than 200k records.

2条回答
  •  悲&欢浪女
    2020-12-11 11:48

    http://www.xsltfunctions.com/xsl/functx_number-of-matches.html

    as documented:

    count(tokenize($arg,$pattern)) - 1
    

    I would write it as:

    count(tokenize($string,$substring)) - 1
    

    in your case:

    count(tokenize('My Name is Rohan and My Home name is also Rohan but one of my firend honey name is also Rohan','Rohan')) - 1
    

    PS: you spelled 'friend' incorrectly.

    I tested this method for my own use-case in XSLT version 2.0, It might also work in 1.0 not sure based on the documentation.

提交回复
热议问题