Quackit Logo
HTML
CSS
Scripting
Database
Hosting
Design
XML
IMCreator - Free Website Builder

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.

Code

Result

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

Code

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

Enjoy this page?

  1. Link to this page (copy/paste into your own website or blog):
  2. Link to Quackit using one of these banner ads.

Thanks for supporting Quackit!