Web Design and Development Forums

background color in xml

This is a discussion on "background color in xml" within the XML, RSS & Atom section. This forum, and the thread "background color in xml are both part of the Program Your Website category.

Old Jun 4th, 2007, 16:10   #1 (permalink)
Junior Member
 
Join Date: May 2007
Location: bahrain
Posts: 25
background color in xml

Hi everyone,

I was doing this example in xml, I don't know how to change the color of data in a table using xsl file ..

like this pic
http://img46.imageshack.us/img46/5739/xsluv8.jpg

the code of the color is at the end
Code: Select all
<xsl:choose>
            <xsl:when test="PRICE[. $le$ 9]">
                        <tr bgcolor="#cccc66">
<th><xsl:value-of select="TITLE" /></th>
<th><xsl:value-of select="ARTIST" /></th>
<th><xsl:value-of select="COUNTRY" /></th>
<th><xsl:value-of select="COMPANY" /></th>
<th><xsl:value-of select="PRICE" /></th>
<th><xsl:value-of select="YEAR" /></th>
</tr>
 
 
         </xsl:when>
 
         <xsl:otherwise>
                      <tr>

<th><xsl:value-of select="TITLE" /></th>
<th><xsl:value-of select="ARTIST" /></th>
<th><xsl:value-of select="COUNTRY" /></th>
<th><xsl:value-of select="COMPANY" /></th>
<th><xsl:value-of select="PRICE" /></th>
<th><xsl:value-of select="YEAR" /></th>

                      </tr> 
         </xsl:otherwise>
       </xsl:choose>

</table>

here is the full code of xsl

Code: Select all
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<body bgcolor='#ffe4c4'>
<table border='2'>
<xsl:for-each select="CATALOG/CD[COUNTRY='UK']"> 

<tr><th>title</th> <th>artist</th> <th>country</th> <th>company</th> <th>price</th> <th>year</th></tr>
<tr><th><xsl:value-of select="TITLE" /></th>
<th><xsl:value-of select="ARTIST" /></th>
<th><xsl:value-of select="COUNTRY" /></th>
<th><xsl:value-of select="COMPANY" /></th>
<th><xsl:value-of select="PRICE" /></th>
<th><xsl:value-of select="YEAR" /></th>
</tr>
<xsl:if match=".[ARTIST='Rod Stewart']">  
      <tr>
        <td><b><xsl:value-of select="TITLE"/></b></td>
        <td><b><xsl:value-of select="ARTIST"/></b></td>
        <td><b><xsl:value-of select="COUNTRY"/></b></td>
        <td><b><xsl:value-of select="COMPANY"/></b></td>
        <td><b><xsl:value-of select="PRICE"/></b></td>
        <td><b><xsl:value-of select="YEAR"/></b></td>
      </tr> 
</xsl:if>

</xsl:for-each>
<xsl:choose>
            <xsl:when test="PRICE[. $le$ 9]">
                        <tr bgcolor="#cccc66">
<th><xsl:value-of select="TITLE" /></th>
<th><xsl:value-of select="ARTIST" /></th>
<th><xsl:value-of select="COUNTRY" /></th>
<th><xsl:value-of select="COMPANY" /></th>
<th><xsl:value-of select="PRICE" /></th>
<th><xsl:value-of select="YEAR" /></th>
</tr>
 
 
         </xsl:when>
 
         <xsl:otherwise>
                      <tr>

<th><xsl:value-of select="TITLE" /></th>
<th><xsl:value-of select="ARTIST" /></th>
<th><xsl:value-of select="COUNTRY" /></th>
<th><xsl:value-of select="COMPANY" /></th>
<th><xsl:value-of select="PRICE" /></th>
<th><xsl:value-of select="YEAR" /></th>

                      </tr> 
         </xsl:otherwise>
       </xsl:choose>

</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
and here is the xml code

Code: Select all
<?xml version="1.0" encoding="ISO8859-1" ?>
<?xml-stylesheet type="text/xsl" href="testxsl2.xsl"?>
<CATALOG>
  <CD>
    <TITLE>Empire Burlesque</TITLE>
    <ARTIST>Bob Dylan</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Columbia</COMPANY>
    <PRICE>10.90</PRICE>
    <YEAR>1985</YEAR>
  </CD>
  <CD>
    <TITLE>Hide your heart</TITLE>
    <ARTIST>Bonnie Tylor</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>CBS Records</COMPANY>
    <PRICE>9.90</PRICE>
    <YEAR>1988</YEAR>
  </CD>
  <CD>
    <TITLE>Greatest Hits</TITLE>
    <ARTIST>Dolly Parton</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>RCA</COMPANY>
    <PRICE>9.90</PRICE>
    <YEAR>1982</YEAR>
  </CD>
  <CD>
    <TITLE>Still got the blues</TITLE>
    <ARTIST>Gary More</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Virgin redords</COMPANY>
    <PRICE>10.20</PRICE>
    <YEAR>1990</YEAR>
  </CD>
  <CD>
    <TITLE>Eros</TITLE>
    <ARTIST>Eros Ramazzotti</ARTIST>
    <COUNTRY>EU</COUNTRY>
    <COMPANY>BMG</COMPANY>
    <PRICE>9.90</PRICE>
    <YEAR>1997</YEAR>
  </CD>
  <CD>
    <TITLE>One night only</TITLE>
    <ARTIST>Bee Gees</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Polydor</COMPANY>
    <PRICE>10.90</PRICE>
    <YEAR>1998</YEAR>
  </CD>
  <CD>
    <TITLE>Sylvias Mother</TITLE>
    <ARTIST>Dr.Hook</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>CBS</COMPANY>
    <PRICE>8.10</PRICE>
    <YEAR>1973</YEAR>
  </CD>
  <CD>
    <TITLE>Maggie May</TITLE>
    <ARTIST>Rod Stewart</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Pickwick</COMPANY>
    <PRICE>8.50</PRICE>
    <YEAR>1990</YEAR>
  </CD>
  <CD>
    <TITLE>Romanza</TITLE>
    <ARTIST>Andrea Bocelli</ARTIST>
    <COUNTRY>EU</COUNTRY>
    <COMPANY>Polydor</COMPANY>
    <PRICE>10.80</PRICE>
    <YEAR>1996</YEAR>
  </CD>
  <CD>
    <TITLE>When a man loves a woman</TITLE>
    <ARTIST>Percy Sledge</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Atlantic</COMPANY>
    <PRICE>8.70</PRICE>
    <YEAR>1987</YEAR>
  </CD>
  <CD>
    <TITLE>Black angel</TITLE>
    <ARTIST>Savage Rose</ARTIST>
    <COUNTRY>EU</COUNTRY>
    <COMPANY>Mega</COMPANY>
    <PRICE>10.90</PRICE>
    <YEAR>1995</YEAR>
  </CD>
  <CD>
    <TITLE>1999 Grammy Nominees</TITLE>
    <ARTIST>Many</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Grammy</COMPANY>
    <PRICE>10.20</PRICE>
    <YEAR>1999</YEAR>
  </CD>
  <CD>
    <TITLE>For the good times</TITLE>
    <ARTIST>Kenny Rogers</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Mucik Master</COMPANY>
    <PRICE>8.70</PRICE>
    <YEAR>1995</YEAR>
  </CD>
  <CD>
    <TITLE>Big Willie style</TITLE>
    <ARTIST>Will Smith</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Columbia</COMPANY>
    <PRICE>9.90</PRICE>
    <YEAR>1997</YEAR>
  </CD>
  <CD>
    <TITLE>Tupelo Honey</TITLE>
    <ARTIST>Van Morrison</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Polydor</COMPANY>
    <PRICE>8.20</PRICE>
    <YEAR>1971</YEAR>
  </CD>
  <CD>
    <TITLE>Soulsville</TITLE>
    <ARTIST>Jorn Hoel</ARTIST>
    <COUNTRY>Norway</COUNTRY>
    <COMPANY>WEA</COMPANY>
    <PRICE>7.90</PRICE>
    <YEAR>1996</YEAR>
  </CD>
  <CD>
    <TITLE>The very best of</TITLE>
    <ARTIST>Cat Stevens</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Island</COMPANY>
    <PRICE>8.90</PRICE>
    <YEAR>1990</YEAR>
  </CD>
  <CD>
    <TITLE>Stop</TITLE>
    <ARTIST>Sam Brown</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>A and M</COMPANY>
    <PRICE>8.90</PRICE>
    <YEAR>1988</YEAR>
  </CD>
  <CD>
    <TITLE>Bridge of Spies</TITLE>
    <ARTIST>T`Pau</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Siren</COMPANY>
    <PRICE>7.90</PRICE>
    <YEAR>1987</YEAR>
  </CD>
  <CD>
    <TITLE>Private Dancer</TITLE>
    <ARTIST>Tina Turner</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Capitol</COMPANY>
    <PRICE>8.90</PRICE>
    <YEAR>1983</YEAR>
  </CD>
  <CD>
    <TITLE>Midt om natten</TITLE>
    <ARTIST>Kim Larsen</ARTIST>
    <COUNTRY>EU</COUNTRY>
    <COMPANY>Medley</COMPANY>
    <PRICE>7.80</PRICE>
    <YEAR>1983</YEAR>
  </CD>
  <CD>
    <TITLE>Pavarotti Gala Concert</TITLE>
    <ARTIST>Luciano Pavarotti</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>DECCA</COMPANY>
    <PRICE>9.90</PRICE>
    <YEAR>1991</YEAR>
  </CD>
  <CD>
    <TITLE>The dock of the bay</TITLE>
    <ARTIST>Otis Redding</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Atlantic</COMPANY>
    <PRICE>7.90</PRICE>
    <YEAR>1987</YEAR>
  </CD>
  <CD>
    <TITLE>Picture book</TITLE>
    <ARTIST>Simply Red</ARTIST>
    <COUNTRY>EU</COUNTRY>
    <COMPANY>Elektra</COMPANY>
    <PRICE>7.20</PRICE>
    <YEAR>1985</YEAR>
  </CD>
  <CD>
    <TITLE>Red</TITLE>
    <ARTIST>The Communards</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>London</COMPANY>
    <PRICE>7.80</PRICE>
    <YEAR>1987</YEAR>
  </CD>
  <CD>
    <TITLE>Unchain my heart</TITLE>
    <ARTIST>Joe Cocker</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>EMI</COMPANY>
    <PRICE>8.20</PRICE>
    <YEAR>1987</YEAR>
  </CD>
</CATALOG>
I need the output to be same as the pic but as you can see the Title and Artist ... etc appear in every row.

I'm new in xml I've just started learning.

Thank you
kool77 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Jun 7th, 2007, 15:43   #2 (permalink)
Junior Member
 
Join Date: May 2007
Location: bahrain
Posts: 25
Re: background color in xml

I made this xsl file now the rows are duplicated twice!! can you help me please?

Code: Select all
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<body bgcolor='#ffe4c4'>
<table border='2'>
<tr><th>title</th> <th>artist</th> <th>country</th> <th>company</th> <th>price</th> <th>year</th></tr>
<xsl:for-each select="CATALOG/CD[COUNTRY='UK']"> 
 
<tr><td><xsl:value-of select="TITLE" /></td>
<td><xsl:value-of select="ARTIST" /></td>
<td><xsl:value-of select="COUNTRY" /></td>
<td><xsl:value-of select="COMPANY" /></td>
<td><xsl:value-of select="PRICE" /></td>
<td><xsl:value-of select="YEAR" /></td>
</tr>
<xsl:if match=".[ARTIST='Rod Stewart']">  
      <tr>
        <td><b><xsl:value-of select="TITLE"/></b></td>
        <td><b><xsl:value-of select="ARTIST"/></b></td>
        <td><b><xsl:value-of select="COUNTRY"/></b></td>
        <td><b><xsl:value-of select="COMPANY"/></b></td>
        <td><b><xsl:value-of select="PRICE"/></b></td>
        <td><b><xsl:value-of select="YEAR"/></b></td>
      </tr> 
</xsl:if>
<xsl:choose>
<xsl:when test="PRICE[. $le$ 9]">
<tr bgcolor='#cccc66'>
<td><xsl:value-of select="TITLE" /></td>
<td><xsl:value-of select="ARTIST" /></td>
<td><xsl:value-of select="COUNTRY" /></td>
<td><xsl:value-of select="COMPANY" /></td>
<td><xsl:value-of select="PRICE" /></td>
<td><xsl:value-of select="YEAR" /></td>
</tr>            
</xsl:when>
<xsl:otherwise>
<tr>
<td><xsl:value-of select="TITLE" /></td>
<td><xsl:value-of select="ARTIST" /></td>
<td><xsl:value-of select="COUNTRY" /></td>
<td><xsl:value-of select="COMPANY" /></td>
<td><xsl:value-of select="PRICE" /></td>
<td><xsl:value-of select="YEAR" /></td>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
kool77 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Jul 7th, 2007, 15:30   #3 (permalink)
Reputable Member
 
Join Date: Dec 2005
Location: U.S.A.
Posts: 123
Re: background color in xml

If I'm not mistaken you could use bgcolor as you have in your body tag. That attribute is usually deprecated but I think in XSLT it is acceptable. Say you wanted to change the background color of the title, I think you can do this...
Code: Select all
<tr><td bgcolor="red"><xsl:value-of select="TITLE" /></td>
Try it out and post back letting us know if it worked for you.
Scott
__________________
Web Design
ScottR is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
color, table

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Having a problem with background color? jaambees CSS Forum 2 Jan 4th, 2008 02:05
background-color kapyrossi CSS Forum 5 Jul 4th, 2007 15:53
IFRAME - background color jansoft HTML Forum 0 May 18th, 2007 11:21
background color kaz CSS Forum 4 Aug 4th, 2005 17:28
background color kaz CSS Forum 1 Apr 20th, 2005 11:43



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 23:07.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59