You can add
<xsl:sort select="position()" order="descending" data-type="number"/>
as the first child of the for-each
to reverse the processing order. If you do this you will also need to change your "last five" test because you now want to process the first five nodes in the reverse-order list. Alternatively it might make more sense to move the "last five" logic into a predicate on the for-each
select expression instead of using an if
:
<xsl:for-each select="(Automation/Run)[position() > last()-5]">
<xsl:sort select="position()" order="descending" data-type="number"/>
This approach will work in XSLT 1.0 as well as 2.0 (you've tagged the question 2.0 but your current stylesheet is version="1.0"
so it's not clear which you actually need).