Search
Web Braintrove
Site Navigation
Home
Products
Tags
Levels
Dates
Authors
5 MOST RECENT
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
Perform a Case-Insensitive String Comparison without Using Translate()
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
Create a Rusted Text Effect Using Styles
Convert Between Time and Decimal
Install Windows 7 Beta onto a Virtual Machine
Create a Drop Cap Using CSS
Enable Themes in Windows Server
Books
XSLT and XPath On The Edge, Unlimited Edition
Building a Generic Report Engine Using SQL Server 2000, XML, and XSLT in ASP.NET
Oracle HTML DB Handbook
XSLT Accelerated
HTML and XHTML Step by Step
Magazines
SQL Server Magazine
Practical Web Design
Net Developers Journal
Soa Web Services Journal
.net: The Internet Magazine
Microsoft MVP
This article has been viewed 666 times.

Display Lists in Columns Vertically Using Individual Cells

Page 2 of 2
Written by Gregory Scot Collins
Tuesday, 19 September 2006, 7:21 AM

Understanding the transform

The key component of this transform is the COLS variable; change its value to adjust the number of columns output. The calculated ROWS variable identifies how many rows are required to display our list items in the specified number of columns. The calculated CELLS variable identifies the total number of cells required to render a complete table (that will often be more than the number of items in the list).
The root template sets up the outer table, and then calls a named template to output the individual items into the table cells. We use a named template here because we want to render a complete table, including empty cells, and we cannot do that via xsl:apply-templates without more complicated code. The named template has a single parameter, NEXT, that is incremented from one to the value of the CELLS variable. You might have noticed the attribute select="1" on the parameter definition; this provides a default value in case the parameter is not passed in to the template. You might have also noticed that we don't pass this parameter in to the template the first time that we call it; thus NEXT defaults to the value 1.
Because table cells are rendered horizontally, and we want to effectively render them vertically, we use the equation for variable POS to identify which list item to display next. The calculated position value might not exist (i.e. is greater than the total number of list items), in which case we render an empty cell. When we reach the maximum number of columns for a single row we must create a new row. As we cannot close and open a new table row traditionally (using the tag combination </tr><tr>) without receiving a tag mismatch error, we output the following to create a new table row, which is processed as text by the XSLT processor but rendered as tags in the final output:
Finally, we call the same named template again, passing in an incremented NEXT parameter. This continues until we have completed our table.

Try it

Applying the transform to our XML results in the following output that correctly renders the list of items vertically in multiple columns with each item in an individual table cell:
Bookmark this Article
StumbleUpon  Stumble It!
Digg  Digg It!
del.icio.us  del.icio.us
List of Figures
Listing 1 - The Items.xml file.
Listing 2 - The Columns-Vertical-Individual.xsl file.
Listing 3 - Generating a new table row.
Screenshot 1 - The list of items rendered in seven columns.
See Also
Display Lists in Columns Vertically Using One Cell per Column
Display Lists in Columns Horizontally Using Individual Cells
Display Lists in Columns Horizontally Using One Cell per Column
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.