Solved

How to I "stripe" columns using XSLT

Posted on 2014-01-13
3
30 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
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 500 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

758 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now