Sort parent nodes XML depends on child nodes values

前端 未结 2 1040
遇见更好的自我
遇见更好的自我 2021-01-20 02:17

I have a following XML

 
  
  
   
     
    
       

        
2条回答
  •  北海茫月
    2021-01-20 02:55

    This transformation implements exactly the stated requirements. It takes special care to preserve the exact order of the elements that are not to be sorted. No other answer at present does this:

    
     
     
    
     
     
    
     
         
           
         
     
    
       
        
    
      
       
       
        
       
      
     
    
    

    When applied on the following XML document (the same as the provided one, but with an additional inserted between Data1 and Data2 so that we can verify the preservation of ordering of the non-sorted elements):

    
        
        
        
            
            
                2222
                field1
            
            
                ABC
                field2
            
        
            
        
            
            
                1111
                field1
            
            
                XYZ
                field2
            
        
    
    

    produces the wanted, correct result -- note that the position of is preserved:

    
       
       
       
          
          
             1111
             field1
          
          
             XYZ
             field2
          
       
       
       
          
          
             2222
             field1
          
          
             ABC
             field2
          
       
    
    

提交回复
热议问题