Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6610125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:48:00+00:00 2026-05-25T19:48:00+00:00

Is it possible to give a different color to each row that has distinct

  • 0

Is it possible to give a different color to each row that has distinct data, using xslt ?

For example, in case there is a table of the form

country        code
india           1
spain           2
germany         3
india           1
sri lanka       4
spain           2

There are 2 rows in which india and spain occur. so, can I color those 2 rows with a particular color and the remaining with different colors? Suppose sri lanka occurs twice, I wish sri lanka rows to have a different color. dis can b done using xslt?

The xml file gets updated dynamically. The xsl reads from the xml file and displays the data in the form of a table. 2 tables will be outputed. I want that, in the 2nd table, each row with distinct ‘Conference name’ should have a different color.

my xsl file

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet  version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">

    <html>
      <head>
        <title>VPGate Media Mixer</title>

        <meta http-equiv="expires" content="0"/>
        <meta http-equiv="pragma" content="no-cache"/>
        <meta http-equiv="cache-control" content="no-cache, must-revalidate"/>
        <meta http-equiv="refresh" content="15"></meta>
        <script src="/Common/common.js\" type="text/javascript"></script>
        <link rel="stylesheet" type="text/css" href="style001.css" />
        <link rel="stylesheet" type="text/css" href="Grid.Default.css" />


      </head>

      <body class="WorkArea">
        <div class="divSummaryHeader" id="SummaryHeader">
          <h1>Media Mixer - VPGate</h1>

          <xsl:for-each select="MMDiagnostics/Conference">
            <h1>
              Media Mixer - <xsl:value-of select="name"/>
            </h1>
          </xsl:for-each>
        </div>

        &#160;



        <div class="RadGrid RadGrid_Default" id="SummaryData" style="position:absolute;width:810px;height:510px;overflow:auto">

          <table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" >
            <tr>
              <input type="button" class="formEditBtn" id="SubBtn" value="Refresh" onclick="window.location=window.location;"/>

            </tr>
            <tr>
              <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;" colspan="2">Conference Summary</td>
            </tr>

            <tr>
              <td>
                <table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0"  >
                  <tr>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference Name</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference ID</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Address</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Port</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Ssrc</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">No Of Participants</td>
                  </tr>

                  <xsl:if test="MediaMixer!= ''">
                    <xsl:for-each select="MediaMixer/Conference">
                      <!--<xsl:sort select="Name"/>-->
                      <xsl:if test="Name !=''">
                        <xsl:if test="(position() mod 2 = 0)">

                          <tr class="rgAltRow SummaryTableDataRow">
                            <td valign = "top">
                              <xsl:value-of select="Name"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="ConfId"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="CompositeAddress"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="CompositePort"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="CompositeSsrc"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="NoOfParticipants"/>
                            </td>
                          </tr>
                        </xsl:if>


                        <xsl:if test="(position() mod 2 = 1)">
                          <td>
                            <tr class="rgRow SummaryTableDataRow">
                              <td valign = "top">
                                <xsl:value-of select="Name"/>
                              </td>
                              <td valign = "top">
                                <xsl:value-of select="ConfId"/>
                              </td>
                              <td valign = "top">
                                <xsl:value-of select="CompositeAddress"/>
                              </td>
                              <td valign = "top">
                                <xsl:value-of select="CompositePort"/>
                              </td>
                              <td valign = "top">
                                <xsl:value-of select="CompositeSsrc"/>
                              </td>
                              <td valign = "top">
                                <xsl:value-of select="NoOfParticipants"/>
                              </td>
                            </tr>
                          </td>
                        </xsl:if>
                      </xsl:if>
                    </xsl:for-each>
                  </xsl:if>
                  <xsl:if test="MediaMixer = ''">
                    <td valign = "top">
                      <xsl:text>No Data </xsl:text>
                    </td>
                  </xsl:if>

                </table>
              </td>
            </tr>
          </table>

          &#160;

          <table border="0" class="rgMasterTable rgClipCells" cellspacing="1" cellpadding="1"  >
            <tr>
              <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;" colspan="2">Conference Details</td>
            </tr>

            <tr>
              <td>

                <table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" >
                  <tr>

                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference Name</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference ID</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Participant ID 1</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Participant ID 2</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Participant Address</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Participant Listening Port</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">MM Listening Port</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">SSRC From Participant</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">SSRC From MM</td>
                  </tr>





                  <xsl:if test="MediaMixer!= ''">

                    <xsl:for-each select="MediaMixer/Conference">


                      <xsl:for-each  select="Participant">

                        <xsl:if test="(position() mod 2 = 0)">
                          <tr class="rgAltRow SummaryTableDataRow">
                            <td valign = "top">
                              <xsl:value-of select="../Name"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="../ConfId"/>
                            </td>

                            <td valign = "top">
                              <xsl:value-of select="ID1"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="ID2"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="ParticipantAddress"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="ParticipantListeningPort"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="MMListeningPort"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="SSRCFromParticipant"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="SSRCFromMM"/>
                            </td>
                          </tr>
                        </xsl:if>

                        <xsl:if test="(position() mod 2 = 1)">
                          <td>
                            <tr class="rgRow SummaryTableDataRow">

                              <td valign = "top">
                                <xsl:value-of select="../Name"/>
                              </td>
                              <td valign = "top">
                                <xsl:value-of select="../ConfId"/>
                              </td>

                              <td valign = "top">
                                <xsl:value-of select="ID1"/>
                              </td>
                              <td valign = "top">
                                <xsl:value-of select="ID2"/>
                              </td>
                              <td valign = "top">
                                <xsl:value-of select="ParticipantAddress"/>
                              </td>
                              <td valign = "top">
                                <xsl:value-of select="ParticipantListeningPort"/>
                              </td>
                              <td valign = "top">
                                <xsl:value-of select="MMListeningPort"/>
                              </td>
                              <td valign = "top">
                                <xsl:value-of select="SSRCFromParticipant"/>
                              </td>
                              <td valign = "top">
                                <xsl:value-of select="SSRCFromMM"/>
                              </td>

                            </tr>
                          </td>
                        </xsl:if>
                      </xsl:for-each>
                    </xsl:for-each>
                  </xsl:if>


                  <xsl:if test="MediaMixer= ''">

                    <td valign = "top">
                      <xsl:text>No Data </xsl:text>
                    </td>
                  </xsl:if>

                </table>
              </td>
            </tr>
          </table>


          &#160;


          <div style="display:none">
            <iframe id="frameUpdate" name="frameUpdate" width="100%"></iframe>
          </div>


        </div>

      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

XML file that gets updated dynamically

<?xml-stylesheet type="text/xsl" href="MMDiagnostics.xslt"?>

<MediaMixer>

  <Conference>
    <Name>Test</Name>
    <ConfId>1002</ConfId>
    <CompositeAddress>238.57.0.1</CompositeAddress>
    <CompositePort>48000</CompositePort>
    <CompositeSsrc>243324353</CompositeSsrc>
    <NoOfParticipants>2</NoOfParticipants>

    <Participant>
      <ID1>abc88C</ID1>
      <ID2>0</ID2>
      <ParticipantAddress>192.168.177.45</ParticipantAddress>
      <ParticipantListeningPort>22004</ParticipantListeningPort>
      <MMListeningPort>45004</MMListeningPort>
      <SSRCFromParticipant>316541</SSRCFromParticipant>
      <SSRCFromMM>26481</SSRCFromMM>
    </Participant>

    <Participant>
      <ID1>piy65R</ID1>
      <ID2>0</ID2>
      <ParticipantAddress>192.168.177.45</ParticipantAddress>
      <ParticipantListeningPort>22004</ParticipantListeningPort>
      <MMListeningPort>45004</MMListeningPort>
      <SSRCFromParticipant>316541</SSRCFromParticipant>
      <SSRCFromMM>26481</SSRCFromMM>
    </Participant>   

  </Conference>

  <Conference>
    <Name>Test3</Name>
    <ConfId>1007</ConfId>
    <CompositeAddress>238.57.0.1</CompositeAddress>
    <CompositePort>48000</CompositePort>
    <CompositeSsrc>243324353</CompositeSsrc>
    <NoOfParticipants>2</NoOfParticipants>

    <Participant>
      <ID1>abxxC</ID1>
      <ID2>0</ID2>
      <ParticipantAddress>192.168.177.45</ParticipantAddress>
      <ParticipantListeningPort>22004</ParticipantListeningPort>
      <MMListeningPort>45004</MMListeningPort>
      <SSRCFromParticipant>316541</SSRCFromParticipant>
      <SSRCFromMM>26481</SSRCFromMM>
    </Participant>

    <Participant>
      <ID1>yyy65R</ID1>
      <ID2>0</ID2>
      <ParticipantAddress>192.168.177.45</ParticipantAddress>
      <ParticipantListeningPort>22004</ParticipantListeningPort>
      <MMListeningPort>45004</MMListeningPort>
      <SSRCFromParticipant>316541</SSRCFromParticipant>
      <SSRCFromMM>26481</SSRCFromMM>
    </Participant>

  </Conference>

  <Conference>
    <Name>Test002</Name>
    <ConfId>1002</ConfId>
    <CompositeAddress>238.57.0.1</CompositeAddress>
    <CompositePort>48005</CompositePort>
    <CompositeSsrc>353324353</CompositeSsrc>
    <NoOfParticipants>2</NoOfParticipants>

    <Participant>
      <ID1>70542151</ID1>
      <ID2>0</ID2>
      <ParticipantAddress>192.168.177.45</ParticipantAddress>
      <ParticipantListeningPort>22004</ParticipantListeningPort>
      <MMListeningPort>45004</MMListeningPort>
      <SSRCFromParticipant>316541</SSRCFromParticipant>
      <SSRCFromMM>26481</SSRCFromMM>
    </Participant>

    <Participant>
      <ID1>70542151</ID1>
      <ID2>0</ID2>
      <ParticipantAddress>192.168.177.45</ParticipantAddress>
      <ParticipantListeningPort>22004</ParticipantListeningPort>
      <MMListeningPort>45004</MMListeningPort>
      <SSRCFromParticipant>316541</SSRCFromParticipant>
      <SSRCFromMM>26481</SSRCFromMM>
    </Participant>
  </Conference>


  </MediaMixer>

output looks like this as of now

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:48:01+00:00Added an answer on May 25, 2026 at 7:48 pm

    This transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:my="my:my" exclude-result-prefixes="my">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:key name="kCountryByName" match="country"
      use="@name"/>
    
     <my:colors>
      <color bgcolor="aqua"/>
      <color bgcolor="blue"/>
      <color bgcolor="fuchsia"/>
      <color bgcolor="gray"/>
      <color bgcolor="green"/>
      <color bgcolor="lime"/>
      <color bgcolor="maroon"/>
      <color bgcolor="navy"/>
      <color bgcolor="purple"/>
      <color bgcolor="yellow"/>
     </my:colors>
    
     <xsl:variable name="vColors"
          select="document('')/*/my:colors/*"/>
    
     <xsl:variable name="vDistinctCountries" select=
      "/*/country
          [generate-id()
          =
           generate-id(key('kCountryByName', @name)[1])
          ]"/>
    
     <xsl:template match="/*">
      <html>
       <table>
        <xsl:apply-templates/>
       </table>
      </html>
     </xsl:template>
    
     <xsl:template match="country">
      <xsl:variable name="vthisName" select="@name"/>
    
      <xsl:variable name="vNum">
       <xsl:for-each select="$vDistinctCountries">
        <xsl:if test="@name = $vthisName">
         <xsl:value-of select="position()"/>
        </xsl:if>
       </xsl:for-each>
      </xsl:variable>
    
      <tr bgcolor="{$vColors[position()=$vNum]/@bgcolor}">
        <td><xsl:value-of select="@name"/></td>
        <td><xsl:value-of select="@continent"/></td>
      </tr>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on this XML document (as no XML document was provided!!!):

    <data>
     <country name="india" continent="Asia"/>
     <country name="spain" continent="Europe"/>
     <country name="germany" continent="Europe"/>
     <country name="india" continent="Asia"/>
     <country name="sri lanka" continent="Asia"/>
     <country name="spain" continent="Europe"/>
    </data>
    

    produces the wanted, correct result:

    <html>
       <table>
          <tr bgcolor="aqua">
             <td>india</td>
             <td>Asia</td>
          </tr>
          <tr bgcolor="blue">
             <td>spain</td>
             <td>Europe</td>
          </tr>
          <tr bgcolor="fuchsia">
             <td>germany</td>
             <td>Europe</td>
          </tr>
          <tr bgcolor="aqua">
             <td>india</td>
             <td>Asia</td>
          </tr>
          <tr bgcolor="gray">
             <td>sri lanka</td>
             <td>Asia</td>
          </tr>
          <tr bgcolor="blue">
             <td>spain</td>
             <td>Europe</td>
          </tr>
       </table>
    </html>
    

    Explanation: Muenchian grouping.

    UPDATE: If there isn’t a known upper limit for the number of distinct countries, use something like this:

    <tr bgcolor="#{$vNum*123456 mod 16777216}">
    

    The complete transformation becomes:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:my="my:my" exclude-result-prefixes="my">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:key name="kCountryByName" match="country"
      use="@name"/>
    
     <my:colors>
      <color bgcolor="aqua"/>
      <color bgcolor="blue"/>
      <color bgcolor="fuchsia"/>
      <color bgcolor="gray"/>
      <color bgcolor="green"/>
      <color bgcolor="lime"/>
      <color bgcolor="maroon"/>
      <color bgcolor="navy"/>
      <color bgcolor="purple"/>
      <color bgcolor="yellow"/>
     </my:colors>
    
     <xsl:variable name="vColors"
          select="document('')/*/my:colors/*"/>
    
     <xsl:variable name="vDistinctCountries" select=
      "/*/country
          [generate-id()
          =
           generate-id(key('kCountryByName', @name)[1])
          ]"/>
    
     <xsl:template match="/*">
      <html>
       <table>
        <xsl:apply-templates/>
       </table>
      </html>
     </xsl:template>
    
     <xsl:template match="country">
      <xsl:variable name="vthisName" select="@name"/>
    
      <xsl:variable name="vNum">
       <xsl:for-each select="$vDistinctCountries">
        <xsl:if test="@name = $vthisName">
         <xsl:value-of select="position()"/>
        </xsl:if>
       </xsl:for-each>
      </xsl:variable>
    
      <tr bgcolor="#{$vNum*1234567 mod 16777216}">
        <td><xsl:value-of select="@name"/></td>
        <td><xsl:value-of select="@continent"/></td>
      </tr>
     </xsl:template>
    </xsl:stylesheet>
    

    and the result now is:

    <html>
       <table>
          <tr bgcolor="#1234567">
             <td>india</td>
             <td>Asia</td>
          </tr>
          <tr bgcolor="#2469134">
             <td>spain</td>
             <td>Europe</td>
          </tr>
          <tr bgcolor="#3703701">
             <td>germany</td>
             <td>Europe</td>
          </tr>
          <tr bgcolor="#1234567">
             <td>india</td>
             <td>Asia</td>
          </tr>
          <tr bgcolor="#4938268">
             <td>sri lanka</td>
             <td>Asia</td>
          </tr>
          <tr bgcolor="#2469134">
             <td>spain</td>
             <td>Europe</td>
          </tr>
       </table>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to give individual cells in a data grid view row different
I am drawing a pie chart, each slice has a different color. I need
What is the best possible way using jQuery to give height and width to
Is it possible for me to give a different name to ApplicationContext.xml? As I
How is it possible to give a jquery-plugin individual local variables, that are accessable
Possible Duplicate: Graph api and equivalent FQL method give different results? I'd like to
It is apparently not possible to give inividual <option> tags different font-family values. I
can i perform select single node from IXMLDOMElement ,if its possible give me one
I was wondering if it is possible to give people something when they join
Possible duplicate: How can i give app store link in my apps before approving

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.