Software is like sex... It's better when it's free.

Blog - Tables, CSS and XSL

Tables, CSS and XSL
If you want to display a list of entities using XSL and css styles in table rows, you can play on modulos using the function position() in XSL.

Suppose the following XML feed listing a set of users:

<?xml version="1.0" encoding="UTF-8"?>

The following css :

table.bo_table_visible {	
  border:1px solid #000;
  border-spacing: 0px;
table.bo_table_visible tr.summary th {
table.bo_table_visible tr td {
  padding:0 10px;
table.bo_table_visible tr.even td, table.bo_table_visible tr th {
table.bo_table_visible tr.even:hover td {
table.bo_table_visible tr.odd td {
table.bo_table_visible tr.odd:hover td {

Simply apply the XSL script below to apply styles to your list of users:

- Apply css with XSL
<xsl:stylesheet xmlns:xsl="" xmlns:php="" version="1.0">
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
  <xsl:template match="root">
        <table class="bo_table_visible">
          <xsl:for-each select="//users/user">
            <xsl:variable name="cssClass">
                <xsl:when test="(position() mod 2) = 0">
            <tr class="{$cssClass}">
              <td><xsl:value-of select="id" /></td>
              <td><xsl:value-of select="login" /></td>
              <td><xsl:value-of select="email" /></td>

Will produce :

Id Login Email
1 lo
2 flo
3 charly
Tags:  cssxmlxsl.
Posted the Tuesday 08 september 2009 17:20:44