sorts in numeric mode. : 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 
sorts in numeric mode.

File: Data.xml
<?xml version="1.0" encoding="utf-8"?>
<data>
  <car id="11"/>
  <car id="6"/>
  <car id="105"/>
  <car id="28"/>
  <car id="9"/>
</data>

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:template match="/">
      <TABLE>
        <xsl:for-each select="//car">
          <xsl:sort data-type="number" select="@id"/>
          <TR>
            <TH>
              <xsl:text>Car-</xsl:text>
              <xsl:value-of select="@id"/>
            </TH>
          </TR>
        </xsl:for-each>
      </TABLE>
    </xsl:template>
</xsl:stylesheet>

Output:

<?xml version="1.0" encoding="UTF-8"?><TABLE><TR><TH>Car-6</TH></TR><TR><TH>Car-9</TH></TR><TR><TH>Car-11</TH></TR><TR><TH>Car-28</TH></TR><TR><TH>Car-105</TH></TR></TABLE>

 
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. Set sort order as ascending
13. sorts in text
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.