Question : Sorting / Filtering XML Using XSL

Need to take an XML document and both re-order and filter elements.

Sample XML is attached, what I want to do is have a complete copy of this XML, with all elements, but is sorted according to salary from low to high. I also only want the 2-4 records returned based on this sort.

All I need is an XSL declaration/stylesheet that I can then do the transform on.

Again, the output needs to be the XML with all parent elements present. I know this is pretty straightforward for someone who is an XSL whiz.

TIA!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
<feed>
 	<companyName>Acme Steel</companyName>
	<copyright>2010</copyright>
	<employees>
		<employee hireDate="04/23/1999">
			<last>Hill</last>
			<first>Phil</first>
			<salary>100000</salary>
		</employee>
		<employee hireDate="09/01/1998">
			<last>Herbert</last>
			<first>Johnny</first>
			<salary>95000</salary>
		</employee>
		<employee hireDate="08/20/2000">
			<last>Hill</last>
			<first>Graham</first>
			<salary>89000</salary>
		</employee>
		<employee hireDate="03/20/2000">
			<last>Schumacher</last>
			<first>Michael</first>
			<salary>189000</salary>
		</employee>
		<employee hireDate="01/20/2000">
			<last>McQueen</last>
			<first>Steve</first>
			<salary>63028</salary>
		</employee>
		<employee hireDate="01/3/2000">
			<last>Hamilton</last>
			<first>Lewis</first>
			<salary>93849</salary>
		</employee>
	</employees>
</feed>

Answer : Sorting / Filtering XML Using XSL

Did you ask only few employee nodes returned? I did not noticed that. Here is a corrected version which returns the first three employee with the lowest salary.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="feed">
	<xsl:copy>
	  <xsl:apply-templates select="*"/>
	</xsl:copy>
</xsl:template>

<xsl:template match="*">
	<xsl:copy-of select="."/>
</xsl:template>
	
<xsl:template match="employees">
	<xsl:copy>
	  <xsl:for-each select="employee">
	  	<xsl:sort select="salary" order="ascending" data-type="number"/>
	  		<xsl:if test="position() &lt; 4">
	  			<xsl:copy-of select="."/>
     		</xsl:if>	  		
      </xsl:for-each>
    </xsl:copy>
</xsl:template>	
</xsl:stylesheet>
Random Solutions  
 
programming4us programming4us