C# XSLT Transforming Large XML Files Quickly

前端 未结 3 1836
我在风中等你
我在风中等你 2021-01-22 09:32

I\'m transforming a > 2GB file with a lookup template in the XSLT. I would like this to run faster but can\'t find any low hanging fruit to improve performance. Any help would b

3条回答
  •  执笔经年
    2021-01-22 10:25

    I think you can simplify the XSLT code

           
                
                
                    
                        
                    
                 
    

    using the template

       
                    
            
        
    

    to

           
                
                
                    
                 
    

    with the template being simplified to

       
            
        
    

    I think that for sure is a more concise and XSLT way of expressing the approach, whether it improves performance is something you would have to test.

    In general with XSLT to improve performance of cross-references/lookups it is recommended to use a key so you would use

    
    

    and then use it as

                
                
                    
                    
                       
                 
    

    I think that would considerable speed up the lookup in a single transformation, as you combine XmlReader and XSLT to run the XSLT many times on as many elements your XmlReader finds I can't tell whether it helps a lot, you would need to try.

    As pointed out in the XSLT 3 suggestion, I would also consider transforming the lookup file first and once to avoid the repetition of all those translate calls to create proper XML element names. Either do that outside of the existing XSLT or do it inside by using a variable and then exsl:node-set to convert the result tree fragment into a variable. But in your case as you run the XSLT repeatedly I think it is probably better to first transform the lookup document outside of the main XSLT, to avoid having to do all those translates again and again.

提交回复
热议问题