Getting a substring AFTER the last occurrence of a character in XSLT

后端 未结 3 1169
悲&欢浪女
悲&欢浪女 2021-01-02 07:26

I have a string in an XML file that looks similar to this:

M:Namespace.Class.Method(Something a, Something b)

The number of peri

3条回答
  •  长发绾君心
    2021-01-02 07:51

    Here is a more efficient solution O(N) vs. O(N^2) for the accepted answer:

    
     
    
     
      
      
      
      
    
      
        
          
        
        
          
    
          
            
            
            
            
          
        
      
     
    
    

    When this transformation is applied on the following XML document:

    M:Namespace.Class.Method(Something a, Something b)
    

    the wanted, correct result is produced:

    Method(Something a, Something b)
    

    Explanation:

    This solution doesn't contain any call to the substring-after() function. Instead, at each step only the one character of the string is compared for equality with the dot character. Because there are at most N characters, this is O(N) -- linear complexity.

    On the contrary, the accepted answer calls the substring-after() function on every step. In the worst case there could be N dots and thus this would be O(N^N) -- quadratic complexity.

    Note: We make the reasonable assumption that in both solutions locating the k-th character of a string is O(1).

提交回复
热议问题