title: Adding alternate colors to a table
body: <p>I have an asp.net web application. The application reads data from an xml. The xml has a reference to a xslt file which takes care of the table design and alignment. I add data to the xml in a dynamic manner. 
  I want every alternate row of the table to have a color (say grey) for readability. I believe it can be done in xslt itself using the line of code </p>
  
  <pre><code> &lt;xsl:if test="(position() mod 2 = 0)"&gt;
  </code></pre>
  
  <p>Can someone please tell me how to do it? I have posted my xslt fully below. </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;
  &lt;xsl:stylesheet  version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;xsl:template match="/"&gt;
  
      &lt;html&gt;
        &lt;head&gt;
          &lt;title&gt;VPGate Media Mixer&lt;/title&gt;
  
          &lt;meta http-equiv="expires" content="0"/&gt;
          &lt;meta http-equiv="pragma" content="no-cache"/&gt;
          &lt;meta http-equiv="cache-control" content="no-cache, must-revalidate"/&gt;
          &lt;meta http-equiv="refresh" content="15"&gt;&lt;/meta&gt;
          &lt;script src="/Common/common.js\" type="text/javascript"&gt;&lt;/script&gt;
          &lt;link rel="stylesheet" type="text/css" href="style001.css" /&gt;
          &lt;link rel="stylesheet" type="text/css" href="Grid.Default.css" /&gt;
  
  
        &lt;/head&gt;
  
        &lt;body class="WorkArea"&gt;       
          &lt;div class="divSummaryHeader" id="SummaryHeader"&gt;
            &lt;h1&gt;Media Mixer - VPGate&lt;/h1&gt;
  
            &lt;xsl:for-each select="MMDiagnostics/Conference"&gt;
              &lt;h1&gt;
                Media Mixer - &lt;xsl:value-of select="name"/&gt;
              &lt;/h1&gt;
            &lt;/xsl:for-each&gt;
          &lt;/div&gt;
  
          &amp;#160;
  
  
  
          &lt;div class="RadGrid RadGrid_Default" id="SummaryData" style="position:absolute;width:630px;overflow:auto"&gt;
  
            &lt;table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" &gt;
              &lt;tr&gt;
                &lt;input type="button" class="formEditBtn" id="SubBtn" value="Refresh" onclick="window.location=window.location;"/&gt;
  
                &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;" colspan="2"&gt;Conference&lt;/td&gt;
                &lt;/tr&gt;
  
                &lt;tr&gt;
                  &lt;td&gt;
                    &lt;table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" &gt;
                      &lt;tr&gt;
                        &lt;td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;"&gt;Conference Name&lt;/td&gt;
                        &lt;td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;"&gt;Conference Id&lt;/td&gt;
                        &lt;td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;"&gt;Composite Address&lt;/td&gt;
                        &lt;td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;"&gt;Composite Port&lt;/td&gt;
                        &lt;td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;"&gt;Composite Ssrc&lt;/td&gt;
                        &lt;td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;"&gt;No Of Participants&lt;/td&gt;
                      &lt;/tr&gt;
  
                      &lt;xsl:for-each select="MediaMixer/Conference"&gt;
                        &lt;!--&lt;xsl:sort select="Name"/&gt;--&gt;
                        &lt;xsl:if test="(position() mod 2 = 0)"&gt;
  
                          &lt;tr class="rgAltRow SummaryTableDataRow"&gt;
                            &lt;td valign = "top"&gt;
                              &lt;xsl:value-of select="Name"/&gt;
                            &lt;/td&gt;
                            &lt;td valign = "top"&gt;
                              &lt;xsl:value-of select="ConfId"/&gt;
                            &lt;/td&gt;
                            &lt;td valign = "top"&gt;
                              &lt;xsl:value-of select="CompositeAddress"/&gt;
                            &lt;/td&gt;
                            &lt;td valign = "top"&gt;
                              &lt;xsl:value-of select="CompositePort"/&gt;
                            &lt;/td&gt;
                            &lt;td valign = "top"&gt;
                              &lt;xsl:value-of select="CompositeSsrc"/&gt;
                            &lt;/td&gt;
                            &lt;td valign = "top"&gt;
                              &lt;xsl:value-of select="NoOfParticipants"/&gt;
                            &lt;/td&gt;
                          &lt;/tr&gt;
                        &lt;/xsl:if&gt;
  
                        &lt;xsl:if test="(position() mod 2 = 1)"&gt;
                          &lt;td bgcolor="#aaaaff"&gt;
                            &lt;tr class="rgAltRow SummaryTableDataRow"&gt;
                              &lt;td valign = "top"&gt;
                                &lt;xsl:value-of select="Name"/&gt;
                              &lt;/td&gt;
                              &lt;td valign = "top"&gt;
                                &lt;xsl:value-of select="ConfId"/&gt;
                              &lt;/td&gt;
                              &lt;td valign = "top"&gt;
                                &lt;xsl:value-of select="CompositeAddress"/&gt;
                              &lt;/td&gt;
                              &lt;td valign = "top"&gt;
                                &lt;xsl:value-of select="CompositePort"/&gt;
                              &lt;/td&gt;
                              &lt;td valign = "top"&gt;
                                &lt;xsl:value-of select="CompositeSsrc"/&gt;
                              &lt;/td&gt;
                              &lt;td valign = "top"&gt;
                                &lt;xsl:value-of select="NoOfParticipants"/&gt;
                              &lt;/td&gt;
                            &lt;/tr&gt;
                          &lt;/td&gt;
                        &lt;/xsl:if&gt;
  
                      &lt;/xsl:for-each&gt;
  
                    &lt;/table&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;
              &lt;/table&gt;
  
              &amp;#160;
  
              &lt;table border="0" class="rgMasterTable rgClipCells" cellspacing="1" cellpadding="1" &gt;
                &lt;tr&gt;
                  &lt;td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;" colspan="2"&gt;Participant&lt;/td&gt;
                &lt;/tr&gt;
  
                &lt;tr&gt;
                  &lt;td&gt;
  
                    &lt;table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" &gt;
                      &lt;tr&gt;
                        &lt;td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;"&gt;ID 1&lt;/td&gt;
                        &lt;td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;"&gt;ID 2&lt;/td&gt;
                        &lt;td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;"&gt;Participant Address&lt;/td&gt;
                        &lt;td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;"&gt;Participant Listening Port&lt;/td&gt;
                        &lt;td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;"&gt;MM Listening Port&lt;/td&gt;
                        &lt;td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;"&gt;SSRC From Participant&lt;/td&gt;
                        &lt;td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;"&gt;SSRC From MM&lt;/td&gt;
                      &lt;/tr&gt;
  
                      &lt;xsl:for-each select="MediaMixer/Conference/Participant"&gt;
  
                        &lt;xsl:if test="(position() mod 2 = 0)"&gt;
  
                          &lt;tr class="rgAltRow SummaryTableDataRow"&gt;
                            &lt;td valign = "top"&gt;
                              &lt;xsl:value-of select="ID1"/&gt;
                            &lt;/td&gt;
                            &lt;td valign = "top"&gt;
                              &lt;xsl:value-of select="ID2"/&gt;
                            &lt;/td&gt;
                            &lt;td valign = "top"&gt;
                              &lt;xsl:value-of select="ParticipantAddress"/&gt;
                            &lt;/td&gt;
                            &lt;td valign = "top"&gt;
                              &lt;xsl:value-of select="ParticipantListeningPort"/&gt;
                            &lt;/td&gt;
                            &lt;td valign = "top"&gt;
                              &lt;xsl:value-of select="MMListeningPort"/&gt;
                            &lt;/td&gt;
                            &lt;td valign = "top"&gt;
                              &lt;xsl:value-of select="SSRCFromParticipant"/&gt;
                            &lt;/td&gt;
                            &lt;td valign = "top"&gt;
                              &lt;xsl:value-of select="SSRCFromMM"/&gt;
                            &lt;/td&gt;
                          &lt;/tr&gt;
                        &lt;/xsl:if&gt;
  
                        &lt;xsl:if test="(position() mod 2 = 1)"&gt;
                          &lt;td bgcolor="#aaaaff"&gt;
                            &lt;tr class="rgAltRow SummaryTableDataRow"&gt;
                              &lt;td valign = "top"&gt;
                                &lt;xsl:value-of select="ID1"/&gt;
                              &lt;/td&gt;
                              &lt;td valign = "top"&gt;
                                &lt;xsl:value-of select="ID2"/&gt;
                              &lt;/td&gt;
                              &lt;td valign = "top"&gt;
                                &lt;xsl:value-of select="ParticipantAddress"/&gt;
                              &lt;/td&gt;
                              &lt;td valign = "top"&gt;
                                &lt;xsl:value-of select="ParticipantListeningPort"/&gt;
                              &lt;/td&gt;
                              &lt;td valign = "top"&gt;
                                &lt;xsl:value-of select="MMListeningPort"/&gt;
                              &lt;/td&gt;
                              &lt;td valign = "top"&gt;
                                &lt;xsl:value-of select="SSRCFromParticipant"/&gt;
                              &lt;/td&gt;
                              &lt;td valign = "top"&gt;
                                &lt;xsl:value-of select="SSRCFromMM"/&gt;
                              &lt;/td&gt;
  
                            &lt;/tr&gt;
                          &lt;/td&gt;
                        &lt;/xsl:if&gt;
                      &lt;/xsl:for-each&gt;
  
                    &lt;/table&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;
              &lt;/table&gt;
  
  
              &amp;#160;
  
  
              &lt;div style="display:none"&gt;
                &lt;iframe id="frameUpdate" name="frameUpdate" width="100%"&gt;&lt;/iframe&gt;
              &lt;/div&gt;
  
  
            &lt;/div&gt;
  
            &lt;/body&gt; 
      &lt;/html&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>