If you’ve worked with XSLT before then you’re more than likely accustomed to using the xsl:sort element when you need to sort strings or numbers within an XML document. This element makes it simple to sort XML data while performing a loop or when calling templates. However, in certain cases when data within an XML document simply needs to be sorted and displayed, XSLT can be overkill. Without using XSLT’s xsl:sort element how can you sort XML data?
This task is actually fairly simple to accomplish in the .NET platform using classes within the System.Xml.XPath namespace such as XPathNavigator and XPathExpression. XPath functionality normally only found in XSLT is exposed by these and several other classes which allows you to navigate through XML documents and even perform sorting operations. This sample application demonstrates how XML data can be sorted using the XPathExpression class.
|