Similar to the previous subelement sort, but I have a few extra layers of nodes. I can't figure out a simple extension to the previous answer that works. http://stackoverflow.com/questions/572854/how-to-sort-a-subelement-of-xml-with-xslt
The simplified input example:
<Iteration>
<Iteration_query-ID>NODE_10008</Iteration_query-ID>
<Iteration_query-def>NODE_10008</Iteration_query-def>
<Iteration_query-len>339</Iteration_query-len>
<Iteration_hits>
<Hit>
<Hit_id>110679166</Hit_id>
<Hit_def>[Roseobacter litoralis Och 149]</Hit_def>
<Hit_len>68</Hit_len>
<Hit_hsps>
<Hsp>
<Hsp_score>300.0</Hsp_score>
<Hsp_evalue>4.94413E-26</Hsp_evalue>
<Hsp_query-from>69</Hsp_query-from>
<Hsp_query-to>272</Hsp_query-to>
</Hsp>
</Hit_hsps>
</Hit>
<Hit>
<Hit_id>114767284</Hit_id>
<Hit_def>[Roseovarius sp. HTCC2601]</Hit_def>
<Hit_len>68</Hit_len>
<Hit_hsps>
<Hsp>
<Hsp_bit-score>127.487</Hsp_bit-score>
<Hsp_score>319.0</Hsp_score>
<Hsp_evalue>3.0968E-28</Hsp_evalue>
<Hsp_query-from>69</Hsp_query-from>
<Hsp_query-to>272</Hsp_query-to>
</Hsp>
</Hit_hsps>
</Hit>
</Iteration_hits>
</Iteration>
I want to sort by one of the Hsp attributes, such as Hsp_score. I've been able to get it to sort, but I can't figure out how to keep it from dropping out some of the Hit nodes:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:import href="identity.xsl"/>
<!--
Iteration/Iteration_hits/Hit/Hit_hsps/Hsp
-->
<xsl:template match="Iteration_hits">
<xsl:copy>
<xsl:apply-templates select="Hit/Hit_hsps/Hsp">
<xsl:sort select="Hsp_score" order="descending"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>