XSLT - remove whitespace from template

前端 未结 8 1854
北恋
北恋 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:39

    This answer may not direct answer to the problem. But a general way solve this issue. Create a template rule:

    
        
        
    
    

    Now call it to remove excess white-space:

    
        
            
                
            
        
    
    

    For example, consider the below XML fragment:

    
    
        
            some text some other text some other text
        
    
    

    And if someone likes to convert it to below text:

    {test{my-element{e1some text} {e2some other text} {e3some other text}}}
    

    Now comes the stylesheet:

    
    
        
    
        
            
            
    
            
        
    
        
            {
            
            
                
                    
                
            
            }
        
    
        
            {
            
            
            }
        
    
        
            
            
        
    
    
    

    After applying the stylesheet, it produce:

    {test{my-element{e1some text} {e2some other text} {e3some other text}}}
    
    {test
    
            some text some other text some other text
    
    }
    

    The output describes how @mode="t1" ( approach) differs from the @mode="t2" (xsl:call-template approach). Hope this helps somebody.

提交回复
热议问题