How to sort XML by attributes using XSLT

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

How to sort XML by attributes using XSLT?

Create an XML document.




    
          


           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 an XSL stylesheet.



Books

 
   
         
        
   
 
 
   
                   
 
            
         
     
 
 

Title Publisher


 

In the example, the ISBN and author attributes are held within the

which is a child element of <book> so we refer to the attributes through their parent element. <xsl:sort select="<A href=" mailto_title="" _cke_saved_href="mailto:title/@ISBN" xsl_sort=""></xsl:sort></book>

must be placed right after the or elements.

element attribute value. The default sort mode is ascending and the default data-type is text.

When sorting numbers, make sure to set the data-type attribute of to a number.

will sort the numbers starting from the smallest.