Thread: sorting issue
View Single Post
  #4 (permalink)  
Old July 28th, 2009, 07:45 AM
Martin Honnen Martin Honnen is offline
Friend of Wrox
Points: 6,408, Level: 34
Points: 6,408, Level: 34 Points: 6,408, Level: 34 Points: 6,408, Level: 34
Activity: 14%
Activity: 14% Activity: 14% Activity: 14%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,190
Thanks: 0
Thanked 235 Times in 234 Posts
Default

Here is a sample stylesheet that sorts all child elements except the 'object' element on the element name:
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  
  <xsl:output indent="yes"/>
  
  <xsl:template match="*[*]">
    <xsl:copy>
      <xsl:copy-of select="object"/>
      <xsl:apply-templates select="*[not(self::object)]">
        <xsl:sort select="name()"/>
      </xsl:apply-templates>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="*[not(*)]">
    <xsl:copy-of select="."/>
  </xsl:template>

</xsl:stylesheet>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
Reply With Quote
The Following User Says Thank You to Martin Honnen For This Useful Post:
nguna (July 28th, 2009)