Search
Web Braintrove
Site Navigation
Home
Products
Tags
Levels
Dates
Authors
5 MOST RECENT
Conditionally Display Different Values In a Single Expression Box
Create a Button With a Blank Label
Create Shared Rules
Perform a Case-Insensitive String Comparison without Using Translate()
Force a Field Value to a Boolean Using Rules
5 MOST POPULAR
Pass Query String Parameters to an ASP.NET Xml Control
Access a Method in a Master Page with Code-Behind
Prevent Namespace Prefixes from Being Copied to the Output
Create Groups in a Drop-Down List Box
Change the Default Action of the Power Button on the Windows Vista Start Menu
5 MOST FORGOTTEN
Hide Deleted Items in the Source Control Explorer
Recover a Dark Picture with a Heavy Color Cast
Prevent Windows Vista from Requesting Your Permission to Continue
Create a Variable with a Unique Sorted Node-Set
Prevent Users from Seeing ASP.NET Error Pages
Books
XSLT Cookbook, Second Edition
XSLT Accelerated
XSLT: Programmer's Reference
XSLT for Dummies
XSLT 1.0 Pocket Reference
Magazines
Practical Web Design
Asp.netpro
Visual Studio Magazine
SQL Server Magazine
Web Site Management And Internet Advertising Trends
Microsoft MVP
This article has been viewed 628 times.

Create a Variable with a Sorted Node-Set

Written by Gregory Scot Collins
Monday, 8 May 2006, 7:02 AM
This article has been tested to work with the following products and versions. No guarantee of compatibility, with or without modification, is offered for products or versions other than those listed.
In complex transforms it might be inconvenient-if not impossible-to accomplish your task without having a variable defined as a sorted node-set. This can be accomplished in two steps: First, a temporary variable is created that sorts the nodes. Second, a node-set is built from the temporary variable. Both steps are required because the first variable does not constitute a node-set and subsequently cannot be used as such, and because we cannot perform sorting within the node-set() function. With our final node-set variable, we can accomplish our design.
The sorted variable can be defined globally at the top of your .xsl file as demonstrated here, or you can define it locally within a template. Let's create some sample files to demonstrate how to create and use a variable with a sorted node-set.

Create the source files

We need a simple XML file to transform. Copy the contents of Listing 1 into a text editor, and then save the file as Customers.xml.
Copy the contents of Listing 2 into a text editor, and then save the file as Customers.xsl. Be sure to save it in the same folder as the Customers.xml file.

Try it

Applying the transform to our XML results in the following output:
SORTED BY NAME:
Beck, Ferdinand
Franklin, Mark
Hamford, Fenwick
Harrisen, Allison
Harrisen, Ben
Jones, Harvey
Smitty, Ronald
Wendell, Alexis
Wendell, Terri
Bookmark this Article
StumbleUpon  Stumble It!
Digg  Digg It!
del.icio.us  del.icio.us
List of Figures
Listing 1 - The Customers.xml file.
Listing 2 - The Customers.xsl file.
See Also
Create a Variable with a Unique Sorted Node-Set
Article Tags
Great Deals
TigerDirect Exclusive Deals, Limited Time Offers, Act Now And Save!
Find all current special offers on Adobe products.
Try SugarSync Free!
Join WebHost4Life.com
TigerDirect
Computers4SURE (4SURE.com - An Office Depot Co.)
Copyright © 2006-2010 Braintrove. All rights reserved. Braintrove, braintrove.com, and the Braintrove logo are trademarks of Gregory Scot Collins in the United States and/or other countries. The names of actual companies and products mentioned herein may be the trademarks of their respective owners. Any rights not expressly granted herein are reserved.