How to sort XML by multiple attributes using XSLT

20+ years of Proud Existence in Web, Intranet, Mobile App development in India

How to sort XML by multiple attributes using XSLT?

The example shows how to sort XML data by multiple attributes @ISBN and @author are held within the same element

. The XSL stylesheet will display the sorted elements in a HTML table.

Create an XML document and link it to a XSL stylesheet.




    
          


           OpenGL Programming Guide Fourth Edition
  
           Addison-Wesley            2004
    

  
          


           Curves and Surfaces for CAGD: A Practical Guide

           Academic Press            2002
      

  
          


           An Introduction to NURBS: With Historical Perspective

           Academic Press            2001
    

  
          


           NURBS: From Projective Geometry to Practical Use

           A K Peters            1999
   

Create a XSL stylesheet.



Books

 
    
        
        
   
 
 
  
            
 
          
       
     
  
 

Title Publisher


 By adding more will sort the output by the first then by the second attribute specified. Identical attribute values are sorted in the order they appear in the XML document.


 

Output:

ISBN
0321173481
0849371643 
1558606696 
1568810849

Author
Michael R. Sweet
Gerald Farin
David Rogers
Gerald Farin