XSLT - remove whitespace from template

前端 未结 8 1855
北恋
北恋 2020-12-02 13:23

I am using XML to store a small contact list and trying to write a XSL template that will transform it into a CSV file. The problem I am having is with whitespace in the out

8条回答
  •  遥遥无期
    2020-12-02 13:42

    As far as removing tabs but retaining separate lines, I tried the following XSLT 1.0 approach, and it works rather well. Your use of version 1.0 or 2.0 largely depends on which platform you're using. It looks like .NET technology is still dependant on XSLT 1.0, and so you're limited to extremely messy templates (see below). If you're using Java or something else, please refer to the much cleaner XSLT 2.0 approach listed towards the very bottom.

    These examples are meant to be extended by you to meet your specific needs. I'm using tabs here as an example, but this should be generic enough to be extensible.

    XML:

    
    
            adslfjksdaf
    
                    dsalkfjdsaflkj
    
                lkasdfjlsdkfaj
    
    

    ...and the XSLT 1.0 template (required if you use .NET):

    
       
     
       
       
       
       
        
           
           
           
             
             
             
           
        
        
          
        
       
                      
      
       
         
         
         
           
      
    
    

    XSLT 2.0 makes this trivial with the replace function:

    
    
     
      
     
    
    

提交回复
热议问题