How to find a word within text using XSLT 2.0 and REGEX (which doesn't have \b word boundary)?

前端 未结 2 402
鱼传尺愫
鱼传尺愫 2021-01-16 03:37

I am attempting to scan a string of words and look for the presence of a particular word(case insensitive) in an XSLT 2.0 stylesheet using REGEX.

I have a list of wo

相关标签:
2条回答
  • 2021-01-16 04:24

    You can use alternation to avoid repetition:

    <xsl:if test="matches($prose, concat('(^|\W)', $word, '($|\W)'),'i')">
    
    0 讨论(0)
  • 2021-01-16 04:29

    If your XSLT 2.0 processor is Saxon 9 then you can use Java regular expression syntax (including \b) with the functions matches, tokenize and replace by starting the flag attribute with an exclamation mark:

    <xsl:value-of select="matches('all foo is bar', '\bfoo\b', '!i')"/>
    

    Michael Kay mentioned that option recently on the XSL mailing list.

    0 讨论(0)
提交回复
热议问题