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: A Guide to XML Transformations
Build Your Own Web Site the Right Way Using HTML & CSS
Integrated HTML and CSS: A Smarter, Faster Way to Learn
Learning XSLT
HTML: Your visual blueprint for designing effective Web pages with HTML, CSS, and XHTML
Magazines
.net: The Internet Magazine
MSDN Magazine
SQL Server Magazine
Web Site Management And Internet Advertising Trends
.net
Microsoft MVP
This article has been viewed 829 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.