XSLT 2.0 to convert CSV to XML format

后端 未结 1 1907
情书的邮戳
情书的邮戳 2020-12-03 12:40

I am are trying to convert an CSV (comma separated file) into XML. For this, I am coding an XSLT template and this is my 1st try at XSLT...

CSV sample:

1条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 13:29

    Here's an XSLT 2.0 option...

    CSV Input (so.csv referenced in the csv-uri param.)

    ClaimRef,HandlerRef,ClaimType,Date,Area,SettleDate,ClaimStatus,ClaimantName
    1,1/1,Liability,08-12-2013,US,23-05-2014,Closed,Mark
    2,1/2,Liability,08-10-2013,UK,23-02-2014,Closed,John
    

    XSLT 2.0 (Use either a well-formed dummy XML doc or the stylesheet itself as input or specify csv2xml as the initial template.)

    
        
        
    
        
        
    
        
            
                
                    
                        
                        
                        
                            
                                
                                    
                                                                                
                                    
                                
                            
                                            
                        
                            
                                
                                    
                                        
                                            
                                            
                                                
                                            
                                        
                                    
                                
                            
                        
                    
                    
                        
                            Error reading "
                            
                            " (encoding "
                            
                            ").
                        
                        
                        
                    
                
            
        
    
    
    

    XML Output

    
       
          1
          1/1
          Liability
          08-12-2013
          US
          23-05-2014
          Closed
          Mark
       
       
          2
          1/2
          Liability
          08-10-2013
          UK
          23-02-2014
          Closed
          John
       
    
    

    Update per comment...

    Here is the same example, but using a variable instead of an external CSV file. You can use this XSLT to test in other online test tools that support XSLT 2.0.

    Example on xsltransform.net

    0 讨论(0)
提交回复
热议问题