Link to home
Start Free TrialLog in
Avatar of sj_hicks
sj_hicksFlag for Australia

asked on

Change HTML text color, reading color from XML data

I've an HTML table which uses an XML island as a data source. It displays fine.  One of the XML elements (called TYPE) contains an RGB color value.  I'd like make the text color for each entry the same as the TYPE color value.  Any ideas?  Thanks.
**** HTML ****
 
<table datasrc="#xmlSOEBase" width="100%" border=0 cellSpacing=0 language=vbscript>
	<tr>
		<td>
			<div><Label datafld="DISPLAY"></Label></div>
		</td>
	</tr>
</table>
 
<xml id="xmlSOEBase"></xml>
 
**** XML ****
<ROOT>
	<BASE>
		<DISPLAY>First entry</DISPLAY>
		<TYPE>762452</TYPE>
	<BASE>
	<BASE>
		<DISPLAY>Second entry</DISPLAY>
		<TYPE>345872</TYPE>
	<BASE>
</ROOT>

Open in new window

Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Data Islands are a very old, Internet Explorer only technique.
It is very unflexible, and you can only map elements to data cells.
You would need a mapping from elements to a class or background colour attribute,
which you can't simply using data islands.

Have you considered XSLT?
It is easy and straightforward, performs a lot better and is a lot more flexible.
Just a little JavaScript and an little XSLT stylesheet and you are done.
Let me know if that is acceptable for you
Avatar of sj_hicks

ASKER

Hi Gertone, thanks for the info.  I'm not too worried about it being IE only, as the HTML being run as an HTA (HTML Application).  I'm including this table as part of a larger HTML document.  I've used basic XSLT before to make an XML file display nicely when you open the XML in a browser.  I looked into using XSLT for this scenario, but I'm not sure how make it work within an existing HTML document (if possible).  Are you able to give me any pointers, samples, links etc?
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I named your xml document "SOEB.xml" and I named the XSLT "SOEB.xsl"
as you can see in the script
Here is the XSLT
Works fine at my desk
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
        <table border="1">
            <tr>
                <th>
                    <xsl:text>DISPLAY</xsl:text>
                </th>
            </tr>
            <xsl:apply-templates/>
        </table>
    </xsl:template>
    <xsl:template match="BASE">
        <tr bgcolor="{TYPE}">
            <td>
                <xsl:value-of select="DISPLAY"/>
            </td>
        </tr>
    </xsl:template>
 
</xsl:stylesheet>

Open in new window

Thanks for the info.  It doesn't quite fit into the HTA structure I'm using (my fault, not yours) - the current setup is quite large and detailed and it would take a quite a bit of rework to implement this functionality using the info you've provided, so I'll give it a miss for now.  However, thanks for your assistance - I've learnt some things I may be able to use in the future.