How to sort XML data by multiple elements using XSLT

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

How to sort XML data by multiple elements using XSLT?

The example explains how to sort XML data by multiple child elements (

and <publisher><strong>) of the same parent element <book>. The XSL stylesheet will display the sorted elements in a HTML table.</book></strong></publisher>

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

Adding more will sort the output by the first and then by the second specified element. Identical elements are sorted in the order they appear in the XML document.

 


Output:

Title                                          
An Introduction to NURBS: With Historical Perspective   
Curves and Surfaces for CAGD: A Practical Guide         
NURBS: From Projective Geometry to Practical Use         
OpenGL Programming Guide Fourth Edition

Publisher
Academic Press
Academic Press
A K Peters
Addison-Wesley