Solved

Change HTML text color, reading color from XML data

Posted on 2009-04-14
6
425 Views
Last Modified: 2013-11-19
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

0
Comment
Question by:sj_hicks
  • 4
  • 2
6 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24145523
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
0
 
LVL 7

Author Comment

by:sj_hicks
ID: 24153437
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?
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 24156589
Here is a basic HTML file,
It has a function that transforms the XML into an HTML table
and overwrites the innerHTML of a div with the transformation result onLoad
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

	

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Select Transform</title>

    <script language="javascript">

      function transF()

      {

         var oXML = new ActiveXObject("Msxml2.DOMDocument");

         var oXSL = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");

         var oTmpl= new ActiveXObject("Msxml2.XSLTemplate");

         var oProc ;
 

	       oXML.async = false;

         oXML.resolveExternals = false;

	       oXML.load("SOEB.xml"); 

	       

         oXSL.async = false;

         oXSL.resolveExternals = false;

         oXSL.load("SOEB.xsl");
 

         oTmpl.stylesheet = oXSL;
 

         oProc = oTmpl.createProcessor();

         oProc.input = oXML;

				 oProc.transform();

         var resHTM = oProc.output;

         document.getElementById("xmlSOEBase").innerHTML = resHTM;

      }

    </script>

</head>
 

<body onload="transF();">

<div id="xmlSOEBase"></div>

</body>

</html>

Open in new window

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24156601
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

0
 
LVL 7

Author Closing Comment

by:sj_hicks
ID: 31571264
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.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24165263
welcome
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now