Sort parent nodes XML depends on child nodes values

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

I have a following XML

 
  
  
   
     
    
       

        
2条回答
  •  Happy的楠姐
    2021-01-20 02:40

    I think you can go with this simple transform:

    
        
        
    
        
    
        
            
                
            
        
    
        
            
                
                    
                    
                
            
        
    
    
    

    When applied to your input (corrected to make it well-formed):

     
        
        
         
             
            
                2222 
                field1
             
            
                ABC 
                field2
             
         
         
             
            
                1111 
                field1
             
            
                XYZ 
                field2
             
         
    
    

    produces:

    
        
        
        
            
            
                1111
                field1
            
            
                XYZ
                field2
            
        
        
            
            
                2222
                field1
            
            
                ABC
                field2
            
        
    
    

    Explanation:

    • Use of identity rule to copy every thing as is.
    • override the required DataN elements and simple application of sort condition based on $field input parameter.
    • data-type for sorting dynamically changes according to element field type

提交回复
热议问题