XSLT 1.0: Sorting by concating portions of date string

前端 未结 2 1409
轻奢々
轻奢々 2021-01-26 00:20

I\'m trying to take XML data and sort elements by their data attribute. Unfortunately the dates come over in mm/dd/yyyy format and are not static lengths. (Jan = 1 instead of

2条回答
  •  花落未央
    2021-01-26 00:33

    Here is one way to do this sorting using a 2-pass transformation (it is possible to do this in a one-pass transformation, but the code would be too-complicated):

    
     
     
    
        
          
             
          
        
    
        
          
            
          
          
        
    
        
         
    
         
         
    
          
          
    
        
          
        
        
    
        
          
             
          
        
    
        
          
           
           
            
           
          
        
    
    

    when this transformation is applied on the provided XML document:

    
        
            
            
            
        
    
    

    the wanted, correct result is produced:

    
       
          
          
          
       
    
    

    Do note:

    1. Multipass transformations in XSLT 1.0 require the use of the vendor-specific xxx:node-set() function to convert the result of a pass from its RTF (Result Transformation Fragment) type to a regular tree (document).

    2. The xxx:node-set() function used in this solution is the ext:node-set() function of EXSLT, which is implemented on most XSLT processors.

提交回复
热议问题