Write an XML to accept student details [Name, ID, Branch and CGPA]. Write an XSL to display the list of students in descending order of their CGPA.
1 Answer

student.xml File

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='cgpa.xsl'?> 
<name> ABC </name>
<id> 001 </id>
<branch> IT </branch>
<cgpa> 9 </cgpa>
<name> PQR </name>
<id> 004 </id>
<branch> Computer </branch>
<cgpa> 7 </cgpa>
<name> XYZ </name>
<id> 006 </id>
<branch> IT </branch>
<cgpa> 10 </cgpa>

cgpa.xsl File

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="https://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
 <h2>Student list in descending order of their CGPA.</h2>
 <table border="1">
 <tr bgcolor="lightblue">
 <xsl:for-each select="class/student">
 <xsl:sort select="cgpa" order="descending" data-type="number"/>
 <td><xsl:value-of select="id"/></td>
 <td><xsl:value-of select="name"/></td>
 <td><xsl:value-of select="branch"/></td>
 <td><xsl:value-of select="cgpa"/></td>
Please log in to add an answer.