Sorting went wrong

I am new to xsl.Here I am trying to sort the list of books respecting "number of pages". I wrote a simple xsl file for this, but it gave me wired output. It sorts some items, it also leaves some items unsorted. Why do I have this conclusion? How can this be fixed?

output:

xml file:

 <?xml version='1.0' encoding='UTF-8'?>
    <?xml-stylesheet type='text/xsl' href='sort.xslt'?>
    <book>
       <entry type='child'>
           <title>amar boi</title>
           <page>100</page>
       </entry>
       <entry type='child'>
           <title>adhunik biggan</title>
           <page>200</page>
       </entry>
       <entry>
           <title>machine design</title>
           <page>10000</page>
       </entry>
         <entry  type='child'>
           <title>amar bondhu rashed</title>
           <page>100</page>
       </entry>
         <entry>
           <title>baler boi</title>
           <page>1000</page>
       </entry>
         <entry>
           <title>fanush</title>
           <page>90</page>
       </entry>
    </book>

      

Xsl file:

<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0' >
<xsl:template match='/'>
<html>
<body>
 <table style='border:1px solid black;'>
     <thead>
        <tr>
           <td>title</td>
           <td>page</td>
        </tr>
     </thead>
     <xsl:apply-templates select='book/entry'>
        <xsl:sort select='page'/>
     </xsl:apply-templates>

 </table>
</body>
</html>
</xsl:template>
<xsl:template match='book/entry'>
    <tr>


        <td><xsl:value-of  select='title'/></td>
        <td><xsl:value-of select='page'/></td>


    </tr>
</xsl:template>
</xsl:stylesheet>

      

+3


source to share


1 answer


You can try adding data-type = 'number' to your xsl: sort:

<xsl:sort select='page'  data-type='number' />

      



The current sort output looks like it is treated as a default string for the data type.

+2


source







All Articles