XSLT 1.0 : Iterate over characters in a string

前端 未结 4 1160
庸人自扰
庸人自扰 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条回答
  •  旧时难觅i
    2021-01-04 02:44

    An XSLT 1.0 Solution using FXSL

    The FXSL library offers a number of generic functions for list processing. Almost all of them have an analog for operating on strings (regarding a string as a list of characters).

    Here is an example using the str-foldl function/template:

    
    
       
    
       
       
        
    
        
    
          
            
            
            
          
        
    
        
             
             
    
             
        
    
    
    

    This transformation calculates the sum of the characters in the string passed as the $pStr parameter and produces the correct result:

    45

    And using the str-map template/function we have the following easy and short solution:

    
       
    
       
    
       
    
       
    
       
         
         
           
           
         
       
    
        
          
    
          
        
    
    
    

    When applied on any XML file (not used), the wanted, correct result is produced:

    S
    o
    m
    e
     
    T
    e
    x
    t
    

提交回复
热议问题