Set sort order as ascending : Sort « XSLT stylesheet « XML

XML
1. CSS Style
2. SVG
3. XML Schema
4. XQuery
5. XSLT stylesheet
Java
XML Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
XML » XSLT stylesheet » Sort 
Set sort order as ascending


File: Data.xml 

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="Transform.xslt" ?>
<neighbours>
  <planet name="Venus">
    <description>
    description
    </description>
    <positionFromSun>2</positionFromSun>
    <diameter> 12104 km (7505 miles)</diameter>
    <moons> 0</moons>
    <meanTemp> 482(900F)</meanTemp>
    <oneDay> 243.01 earth days</oneDay>
    <oneYear> 224.7 earth days</oneYear>
  </planet>

</neighbours>

File: Transform.xslt

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:import href="planetsToXHTML.xsl"/>
  <xsl:output method="html" version="4.0" indent="yes"/>
  <xsl:template match="neighbours">
    <html>
      <head>
        <title>Sorted planets</title>
      </head>
      <body>
        <h1>My sorted list of planets</h1>
        <xsl:apply-templates>
          <xsl:sort select="substring-before(meanTemp/text(), 'C')" order="ascending" data-type="number"/>
        </xsl:apply-templates>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

Output:

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Sorted planets</title>
      </head>
   <body>
      <h1>My sorted list of planets</h1>
      
      
      
      
      description
      
      2
       12104 km (7505 miles)
       0
       482(900F)
       243.01 earth days
       224.7 earth days
      
   </body>
</html>

 
Related examples in the same category
1. Sort value first then output
2. sort select="salary" data-type="number" order="descending"
3. Sort by two columns
4. Sort by attribute value
5. Sort by substring
6. sort by different level of node
7. sort element by data type
8. for each sort descending
9. sort with current-grouping-key() function
10. sort by attribute
11. Sort by element text
12. sorts in text
13. sorts in numeric mode.
14. sorts upercase letters first
15. sorts lowercase letters first
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.