Sorting criterion can be given with the sort attribute. The path of sorting criterion is given relatively to the path selected by xsl:apply-templates.
|
XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/> <xsl:template match="/"> <xsl:apply-templates select="/aaa/bbb"> <xsl:sort select="@x"/> </xsl:apply-templates> </xsl:template> <xsl:template match="bbb"> <bbb> <xsl:value-of select="."/> </bbb> </xsl:template> </xsl:stylesheet> |
|
|
XML
<aaa> <bbb x="d">1</bbb> <bbb x="b">2</bbb> <bbb x="c">3</bbb> <bbb x="a">4</bbb> </aaa> |
Output
<bbb>4</bbb> <bbb>2</bbb> <bbb>3</bbb> <bbb>1</bbb> |
| Previous chapter: | Number Formatting |
| Next chapter: | Axes |
| Previous page: | Sorting nodes - xsl:sort |
| Next page: | Reverse sorting |