?
Solved

How to I "stripe" columns using XSLT

Posted on 2014-01-13
3
Medium Priority
?
64 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
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 …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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).
Suggested Courses

764 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