Search
Web Braintrove
Site Navigation
Home
Products
Tags
Levels
Dates
Authors
5 MOST RECENT
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
Preview and Open Forms after Upgrading to Internet Explorer 8
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
Install Windows 7 Beta onto a Virtual Machine
Configure Lab Color Mode Defaults for Braintrove Articles
Permanently Change the Default Styles for New Word Documents
Enable Themes in Windows Server
Use Logical Operators in Place of Conditional Expressions
Books
HTML & XHTML: The Complete Reference
Learning Web Design : A Beginner's Guide to HTML, Graphics, and Beyond
Head First HTML with CSS & XHTML
Build Your Own Web Site the Right Way Using HTML & CSS
Sams Teach Yourself HTML & XHTML in 24 Hours
Magazines
Inside Visual Basic
Inside Web Development
Soa Web Services Journal
Practical Web Design
SQL Server Magazine
Microsoft MVP
This article has been viewed 655 times.

Get the Min or Max Value of a List Node

Written by Gregory Scot Collins
Wednesday, 23 August 2006, 11:04 PM
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.
One frustration developers have with XSLT 1.0 is the lack of useful functions available for data processing. Functions to get the min or max value of a list node are among those missing. Luckily these two functions are easily represented using XPath expressions, allowing us to achieve our desired results. Let's examine how to define variables to get the min or max value of a list of numbers. If you need to get the oldest or newest value of a list of dates, please refer to Get the Oldest or Newest Date Value of a List Node.

Create the Pages.xml file

We need a simple XML file to transform that contains a list of items from which we will get our min or max value. Copy the contents of Listing 1 into a text editor, and then save the file as Pages.xml.

Create the Min-Max.xsl file

Now we need a transform that will define variables which get our min or max value. If you prefer, you may use the XSLT constructs required to get the oldest or newest date value instead of the XPath expessions shown in Listing 2.
Copy the contents of Listing 2 into a text editor, and then save the file as Min-Max.xsl. Be sure to save it in the same folder as the Pages.xml file.

Understanding the transform

For the MIN_VISITS and MAX_VISITS variables we get the desired value from an XPath expression that uses a filter to compare the value of each visit attribute against every preceding and following sibling. After looping through each visit attribute, the correct min or max value is returned to the variable.

Try It

Applying the transform to our XML results in the following output that correctly gets the min and max values of the visit attribute in our list:
The fewest visits to a page were 133.
The most visits to a page were 316.
Bookmark this Article
StumbleUpon  Stumble It!
Digg  Digg It!
del.icio.us  del.icio.us
List of Figures
Listing 1 - The Pages.xml file.
Listing 2 - The Min-Max.xsl file.
See Also
Get the Oldest or Newest Date Value of a List Node
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.