CSV to XML using xslt - how to have incrementing column name

前端 未结 4 1395
小鲜肉
小鲜肉 2021-01-03 13:42

I have this xslt to convert a csv to xml, works fine, except the tag is the same for all columns. I need it to increment like this


  

        
4条回答
  •  醉酒成梦
    2021-01-03 14:01

    Although the OP is probably looking for an XSLT 1.0 solution, for interest here is an XSLT 2.0 solution. This solution requires you to download my csv-to-xml library style-sheet from here, which is discussed in this blog entry.

    With this as the input document, referred to in the style-sheet with uri 'gangt.csv' (use a parameter or adapt as you require)...

    gangt.csv

    3779490,916705,CS,60,34.89,Sauce/Cholula
    5918104,918958,CS,6,20.63,Pasta/Fresh/Cavatelli/6#/Frozen
    5064774,920723,CS,10,45.5,Cheese/Oaxaca
    3422752,925230,EA,8,69.6,Chipotle/Powder/Ground
    5955640,BB171,CS,30,50.7,Butter/Unsalted
    5295326,BC110005,CS,6000,54.95,Oil/Olive/Finishing
    

    Style-sheet

    ...this XSLT 2.0 style-sheet...

    
    
    
    
    
    
     
       
     
    
    
    
     
       
     
    
    
    
     
       
     
    
    
          
    

    Output

    ...produces this output document...

    
       
          3779490
          916705
          CS
          60
          34.89
          Sauce/Cholula
       
       
          5918104
          918958
          CS
          6
          20.63
          Pasta/Fresh/Cavatelli/6#/Frozen
       
       
          5064774
          920723
          CS
          10
          45.5
          Cheese/Oaxaca
       
       
          3422752
          925230
          EA
          8
          69.6
          Chipotle/Powder/Ground
       
       
          5955640
          BB171
          CS
          30
          50.7
          Butter/Unsalted
       
       
          5295326
          BC110005
          CS
          6000
          54.95
          Oil/Olive/Finishing
       
    
    

提交回复
热议问题