Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to I "stripe" columns using XSLT

Posted on 2014-01-13
3
Medium Priority
?
67 Views
Last Modified: 2016-05-18
Given an XML "table" with an arbitrary and unknown number of columns, what is the best way to handle column even/odd formatting so that the results are striped columns?
0
Comment
Question by:heykjo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39777470
CSS
	tr td:nth-child(odd){ 
		background: blue;
	}
	tr td:nth-child(even){
		background: green;
	}	

Open in new window


This is CSS3 so won't work in IE8 and lower.
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 39777515
well, given the question clearly says "using XSLT", I can offer you a XSLT solution that works regardless of the browser version

the trick is to use "mod" on position of cells inside the row (I assume your XML model is row based not column based, if it is column based, you need to pivot in order to get html anyway)

on the cell you do this (assuming an apply templates for the cells only, and assuming cell as the cell element name in your XML)
<xsl:template match="cell">
<td>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="position() mod 2 = 1">cell-odd</xsl:when>
<xsl:otherwise>cell-even</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="."/>
</td>
</xsl:template>

so you can have in your css a style for cell-even and cell-odd, setting the background color
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to count occurrences of each item in an array.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question