XSLT 1.0 : Iterate over characters in a string

前端 未结 4 1161
庸人自扰
庸人自扰 2021-01-04 02:12

I need to iterate over the characters in a string to build an XML structure.

Currently, I am doing this :


          


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-04 02:42

    If the string length is not huge, you can use a recursively called template to achieve this, passing the index of the character to be processed as parameter into the template.

    Like so:

    
        Some text
        
        
            
                
            
            
                
                
            
        
    
    

    If the string is longer than that, you can use a similar approach but with a divide-and-conquer algorithm, so that you have a maximum recursion depth of log2(string-length), like so:

    
        Some text
        
        
        
            
                
                    
                
            
            
                
                
                    
                    
                    
                
                
                    
                    
                    
                
            
        
    
    

提交回复
热议问题