XSLT <sort> Element

The XSLT <xsl:sort> element allows you to sort the output of the <xsl:for-each> element.

<xsl:sort> Example

Here, we use <xsl:for-each> to loop through each tutorial element, and <xsl:sort> to sort by the name node. We then use the <xsl:value-of> to extract data from the name node.

Result

So, let's see what would happen if we applied the above XSLT document to the following XML document:

Before:

This is how the contents would be displayed before applying the <xsl:sort> element:

XML Tutorial
HTML Tutorial

After:

This is how the contents would be displayed after applying the <xsl:sort> element:

HTML Tutorial
XML Tutorial