You can use xsl:sort
to sort matching nodes. This will allow you to sort by your val
element. However, XPath 1.0 does not have a date data-type. A reasonable solution to this problemm is to split your date into its year, month and day components and sort by each individually. The following should do the trick:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="root">
<xsl:copy>
<xsl:apply-templates>
<xsl:sort select="val" data-type="number" order="descending"/>
<!-- year sort -->
<xsl:sort select="substring(date,7,4)" data-type="number" />
<!-- month sort -->
<xsl:sort select="substring(date,4,2)" data-type="number" />
<!-- day sort -->
<xsl:sort select="substring(date,1,2)" data-type="number" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…