For an XML file that has the following structure
<?xml version="1.0" encoding="UTF-8">
<farm xmlns:my="mynamespace.com" >
<pen>
<sheep> 3 </sheep>
<cow> 3</cow>
<pig> 2</pig>
<chicken> 5</chicken>
</pen>
<pen>
<sheep> 12 </sheep>
<cow> 1</cow>
<pig> 2</pig>
<chicken> 4</chicken>
</pen>
<pen>
<sheep> 4 </sheep>
<cow> 4</cow>
<pig> 1</pig>
<chicken> 2</chicken>
</pen>
</farm>
I have an xsl style sheet that loops through each pen node(for-each), generates an id for each animal type, i.e. sheep,cow,pig and chicken and counts the total. Generating a table as below
ANIMAL | VALUE
-----------------
pig | 5
cow | 8
sheep | 19
chickens | 11
Now I would like to have this resultset sorted, by the value column
Is it possible to do the equivalent of a subquery using XSL?
This XSLT 1.0 transformation:
when applied on the provided XML document:
produces the wanted, correct result:
Explanation: Proper use of the Muenchian method for grouping.