XPath/XSLT contains() for multiple strings

前端 未结 2 739
时光说笑
时光说笑 2021-01-21 13:46

Does contains() work for multiple words stored in a variable? Will the below one work? If it won\'t work, please help me with a solution.



        
2条回答
  •  后悔当初
    2021-01-21 14:29

    Assuming that you're looking to do a logical OR of substring containment...

    First of all, this select is likely wrong1:

    
    

    It's looking for an element named footballvolleyballchesscarrom. If you're trying to set games to the string footballvolleyballchesscarrom, change it to this:

    
    

    Then, use either

    XSLT 1.0

    CORRECT
    

    or

    XSLT 2.0

    CORRECT
    

    to test whether $games contains one of your multiple substrings.


    1 If you really intended to select (possibly multiple) elements from the input XML here, there is another XSLT 2.0 option for testing the selected sequence against a set of possible values. If your input XML were, say,

    
      football
      volleyball
      chess
      carrom
    
    

    then this template,

    
      
      CORRECT
    
    

    would output CORRECT because among the string values of the selected elements is at least one of chess or carrom.

提交回复
热议问题