for each sort descending : 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 
for each sort descending



File: Data.xml
<?xml version="1.0"?>
<results group="A">
  <match>
    <date>10-Jun-98</date>
    <team score="2">Brazil</team>
    <team score="1">Scotland</team>
  </match>
  <match>
    <date>10-Jun-98</date>
    <team score="2">Morocco</team>
    <team score="2">Norway</team>
  </match>
  <match>
    <date>16-Jun-98</date>
    <team score="1">Scotland</team>
    <team score="1">Norway</team>
  </match>
</results>

File: Transform.xslt
<?xml version="1.0"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  <xsl:template match="*">
    <xsl:comment>
      <xsl:value-of select="name()" />
      <xsl:for-each select="ancestor::*">
        <xsl:sort select="position()" order="descending" />
        <xsl:text> within </xsl:text>
        <xsl:value-of select="name()" />
      </xsl:for-each>
    </xsl:comment>
    <xsl:apply-templates />
  </xsl:template>

</xsl:transform>

Output:

<?xml version="1.0" encoding="UTF-8"?><!--results-->
  <!--match within results-->
    <!--date within match within results-->10-Jun-98
    <!--team within match within results-->Brazil
    <!--team within match within results-->Scotland
  
  <!--match within results-->
    <!--date within match within results-->10-Jun-98
    <!--team within match within results-->Morocco
    <!--team within match within results-->Norway
  
  <!--match within results-->
    <!--date within match within results-->16-Jun-98
    <!--team within match within results-->Scotland
    <!--team within match within results-->Norway
  

 
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. sort with current-grouping-key() function
9. sort by attribute
10. Sort by element text
11. Set sort order as ascending
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.