Search
Web Braintrove
Site Navigation
Home
Products
Tags
Levels
Dates
Authors
5 MOST RECENT
Create Shared Rules
Perform a Case-Insensitive String Comparison without Using Translate()
Force a Field Value to a Boolean Using Rules
Quickly Crop to a Shadow
Sum Repeating Time Values
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
Recover a Dark Picture with a Heavy Color Cast
Hide Deleted Items in the Source Control Explorer
Prevent Windows Vista from Requesting Your Permission to Continue
Create a Variable with a Unique Sorted Node-Set
Get the Oldest or Newest Date Value of a List Node
Books
XSLT Cookbook
Web Design with XML: Generating Webpages with XML, CSS, XSLT and Format
XML, XSLT, Java, and JSP: A Case Study in Developing a Web Application
XPath 2.0 Programmer's Reference
XSLT Quickly
Magazines
Inside Visual Basic
Practical Web Design
Soa Web Services Journal
.net: The Internet Magazine
Inside Web Design
Microsoft MVP
This article has been viewed 497 times.

Create a Variable with a Unique Sorted Node-Set

Written by Gregory Scot Collins
Monday, 8 May 2006, 7:27 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, while filtering for unique values. 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 unique 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 UNIQUE CITIES:
Centerville
Fairview
Midway
Riverside
Salem
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 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.