Thread: sorting nodes
View Single Post
  #10 (permalink)  
Old July 8th, 2009, 02:19 AM
mrame mrame is offline
Friend of Wrox
Points: 949, Level: 11
Points: 949, Level: 11 Points: 949, Level: 11 Points: 949, Level: 11
Activity: 17%
Activity: 17% Activity: 17% Activity: 17%
 
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 205
Thanks: 9
Thanked 22 Times in 22 Posts
Thumbs up

Try this:

Code:
<xsl:key name="k" match="employee" use="TypeCde"/>

<xsl:template match="Company">
<xsl:copy>
<Employees>
<xsl:for-each select="//employee[generate-id(.) = generate-id(key('k',TypeCde)[1])]">
<xsl:for-each select="key('k', TypeCde)">
<xsl:sort select="salary" data-type="number" order="descending"/>
<xsl:if test="position() = 1">
<xsl:copy>
<xsl:variable name="type" select="TypeCde"></xsl:variable>
<xsl:variable name="sal" select="salary"></xsl:variable>
<xsl:copy-of select="$type"/>
<xsl:copy-of select="$sal"/>
<xsl:copy-of select="../Id"/>
<xsl:copy-of select="../..//Id[..//TypeCde = $type][not(..//salary = $sal)]"/>
</xsl:copy>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</Employees>
</xsl:copy>
</xsl:template>


There may be better solution from experts.
__________________
Rummy
Reply With Quote