Solved

How to I "stripe" columns using XSLT

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn how to dynamically set the form action using jQuery.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

808 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