XSLT <sort> Element Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report XSLT <sort> Element is used to sort the node which is selected. The XSLT <sort> element is added inside the <xsl:for-each> element. Syntax: <xsl:sort select= node order="ascending" | "descending" case-order="upper-first" | "lower-first" lang=XML:LANG-CODE data-type="text" | "number" />Parameters: select: It is used to select a node with which we sort the node. order: It specifies the ordered sequence.case-order: It specifies the order in which upper case and lower case letters are considered first. lang: It specifies language is to be used by the sort. data-type: It defines which is first sorted alphabets or numbers. Example 1: In this example, we will sort the element of XML with the help of the age node. Save Both files as mentioned and open xsl file on the Browser, it will show the output as shown below: XML <!--File: Test.xml--> <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl "href="Rule.xsl" ?> <student> <s> <name> Divyank Singh Sikarwar </name> <branch>CE</branch> <age>18</age> <city> Agra </city> </s> <s> <name> Aniket Chauhan </name> <branch> CSE</branch> <age>20</age> <city> Shahjahanpur </city> </s> <s> <name> Simran Agarwal</name> <branch> CSE</branch> <age>23</age> <city> Buland Shar</city> </s> <s> <name> Abhay Chauhan</name> <branch>ME</branch> <age>17</age> <city> Shahjahanpur</city> </s> <s> <name> Himanshu Bhatia</name> <branch>IT</branch> <age>25</age> <city> Indore</city> </s> </student> XML <!--File: Rule.xsl--> <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h1 align="center">Students' Basic Details</h1> <table border="3" align="center" > <tr> <th>Details</th> </tr> <xsl:for-each select="student/s"> <xsl:sort select="age"/> <tr> <td> <xsl:apply-templates select="name"/> <xsl:apply-templates select="branch"/> <xsl:apply-templates select="age"/> </td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> <xsl:template match="name"> Name: <span style="font-family:cursive;color:#ff0000"> <xsl:value-of select="."/> </span> <br /> </xsl:template> <xsl:template match="branch"> Branch: <span style="font-family:serif;color:#0ff000"> <xsl:value-of select="."/> </span> <br /> </xsl:template> <xsl:template match="age"> Age: <span style="font-family:fantsy;color:#0000ff"> <xsl:value-of select="."/> </span> <br /> </xsl:template> </xsl:stylesheet> Output: sort Example 2: In this example, we will sort the elements of XML in descending order with name node. Save Both files as mentioned and open xsl file on the Browser, it will show the output as shown below: XML <!--File: Test.xml--> <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl "href="Rule.xsl" ?> <student> <s> <name> Divyank Singh Sikarwar </name> <branch> CSE</branch> <age>18</age> <city> Agra </city> </s> <s> <name> Aniket Chauhan </name> <branch> CSE</branch> <age> 20</age> <city> Shahjahanpur </city> </s> <s> <name> Simran Agarwal</name> <branch> CSE</branch> <age> 23</age> <city> Buland Shar</city> </s> <s> <name> Abhay Chauhan</name> <branch> CSE</branch> <age> 17</age> <city> Shahjahanpur</city> </s> <s> <name> Himanshu Bhatia</name> <branch> IT</branch> <age> 25</age> <city> Indore</city> </s> </student> XML <!--File: Rule.xsl--> <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h1 align="center">Students' Basic Details</h1> <table border="3" align="center" > <tr> <th>Name</th> <th>Branch</th> <th>Age</th> </tr> <xsl:for-each select="student/s"> <xsl:sort select="name" order="descending"/> <tr> <td> <xsl:apply-templates select="name"/> </td> <td> <xsl:apply-templates select="branch"/> </td> <td> <xsl:apply-templates select="age"/> </td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> <xsl:template match="name"> <span style="color:#ff0000"> <xsl:value-of select="."/> </span> <br /> </xsl:template> <xsl:template match="branch"> <span style="color:#0ff000"> <xsl:value-of select="."/> </span> <br /> </xsl:template> <xsl:template match="age"> <span style="color:#0000ff"> <xsl:value-of select="."/> </span> <br /> </xsl:template> </xsl:stylesheet> Output: sort Comment More infoAdvertise with us Next Article jQWidgets jqxSortable sort event S singhanuj78276 Follow Improve Article Tags : HTML Web technologies-HTML and XML Geeks Premier League 2023 Similar Reads script.aculo.us Sorting Elements Sortable provides the ability to user to create many draggable elements within the container. When you create a Sortable, it automatically creates the corresponding Draggable and Droppable for the container. Syntax:Â Â Sortable.create('container_id', {options}); Sortable Options: OptionsDescriptionta 2 min read jQWidgets jqxSortable sort event jQWidgets is a JavaScript framework for making web-based applications for PC and mobile devices. It is a very powerful and optimized framework, platform-independent, and widely supported. jqxSortable represents a jQuery plugin that allows you to reorder elements in an Html list or div tags using the 1 min read How to sort HTML elements by data-attribute ? In this article let us see how we can sort HTML elements using data-attribute.We can sort the HTML elements like lists or any other using the data attribute. The data attribute consists of 2 parts which are the prefix and suffix, the prefix data- is compulsory and the suffix of data- can be any cust 3 min read HTML <ol> Tag The HTML <ol> tag defines an ordered list. An ordered list can be numerical or alphabetical. It's a fundamental HTML element used for structuring content and providing sequential organization. The numbering format can be customized using attributes like type and start, ensuring flexibility in 2 min read HTML <ol> Tag The HTML <ol> tag defines an ordered list. An ordered list can be numerical or alphabetical. It's a fundamental HTML element used for structuring content and providing sequential organization. The numbering format can be customized using attributes like type and start, ensuring flexibility in 2 min read How to Sort in Golang? Sorting is a common operation in programming that organizes elements in a certain order. In Go, also known as Golang, the sort package provides functionalities for sorting arbitrary sequences. This article will guide you through the process of sorting in Golang.What is Sorting?Sorting is the process 4 min read Like