XSLT for each letter in a string

前端 未结 6 1132
一向
一向 2021-01-11 17:44

I\'m writing an XSLT transformation (for XSL-FO), and need to repeat something for each letter in a string value, for example:

If string is stored in MyData/My

6条回答
  •  盖世英雄少女心
    2021-01-11 18:44

    You can try this dirt-ugly hack that has proven to work time and again:

    
      
        
      
    
    

    This will work if //* matches more nodes than the number of characters in your string... Of course, this would also deserve the odd line of comment for the poor fellow reading your code afterwards... ;-)

    Note: I know there are XSLT purists out there. But when you need to get the job done and don't care much about the hyper-verbosity of XSLT, then sometimes these tricks are awesome! IMO

    Note also: I have raised a performance question here, to see if iteration or recursion performs better: XSLT iteration or recursion performance

提交回复
热议问题