Search
Web Braintrove
Site Navigation
Home
Products
Tags
Levels
Dates
Authors
5 MOST RECENT
Locate the Design Checker Task Pane in InfoPath 2010
Locate Conditional Formatting and Custom Validation in InfoPath 2010
Conditionally Display Different Values In a Single Expression Box
Create a Button With a Blank Label
Create Shared Rules
5 MOST POPULAR
Access a Method in a Master Page with Code-Behind
Pass Query String Parameters to an ASP.NET Xml Control
Prevent Namespace Prefixes from Being Copied to the Output
Create Groups in a Drop-Down List Box
Configure IIS 7 for Custom Error Pages
5 MOST FORGOTTEN
Install Windows 7 Beta onto a Virtual Machine
Group Dates by Year, Month and Day
Configure Lab Color Mode Defaults for Braintrove Articles
Create a Monochromatic Dream Text Effect Using Styles
Combine Multiple Sums Into a Single Function
Books
XSLT and XPath On The Edge, Unlimited Edition
Inside XSLT
XSLT 1.0 Pocket Reference
Learning XSLT
Sams Teach Yourself XSLT in 21 Days
Magazines
Practical Web Design
.net: The Internet Magazine
Inside Web Development
Inside Visual Basic
Soa Web Services Journal
Microsoft MVP
This article has been viewed 526 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.