Solved

XSL/XML Change the background-color of a cell based on the value in the cell

Posted on 2004-08-08
5
1,429 Views
Last Modified: 2008-01-09
I want to change the background-color of each cell to light gray if the value in the cell is zero (0)

Please show me an example code

Thanks
0
Comment
Question by:leslynf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 4

Author Comment

by:leslynf
ID: 11745753
Here are the examples for my xml and xsl files

XML:

<dataroot>
<qryDistrict>
<State>AR</State>
<District>Cornell SD</District>
<Value>300</Value>
<Schools>15</Schools>
<Teachers>35</Teachers>
<Students>1,500</Students>
</qryDistrict>
<qryDistrict>
<State>AR</State>
<District>Davis SD</District>
<Value>0</Value>
<Schools>0</Schools>
<Teachers>0</Teachers>
<Students>0</Students>
</qryDistrict>
</dataroot>

XSL:

<xsl:for-each select="$pNodes">
      <xsl:sort select="*[local-name() = $pSortByState]" data-type="text" order="ascending"/>
      <xsl:sort select="*[local-name() = $pSortBy]" data-type="{$pType}" order="{$pDirection}"/>
      <TR>
           <TD ALIGN="left">
            <A href="AEPNonPartDistricts.html?state={State}"><xsl:value-of select="State"/></A>
           </TD>
           <TD ALIGN="left">
            <A href="AEPbySchool.html?district={District}&amp;state={State}"><xsl:value-of select="District"/></A>
           </TD>
           <TD ALIGN="right">$<xsl:value-of select="format-number(Value, '###,###,###,##0')"/></TD>
           <TD ALIGN="right"><xsl:value-of select="format-number(Schools , '###,###,###,##0')"/></TD>
           <TD ALIGN="right"><xsl:value-of select="format-number(Teachers , '###,###,###,##0')"/></TD>
           <TD ALIGN="right"><xsl:value-of select="format-number(Students , '###,###,###,##0')"/></TD>
      </TR>
</xsl:for-each>
0
 
LVL 5

Accepted Solution

by:
conorj earned 500 total points
ID: 11745887
Assuming you haven't already declared an attribute style for the td element then you could try the following:

...........
<xsl:template match="td">
    <td>
        <xsl:if test=". = 0">
            <xsl:attribute name="style">background-color: #C0C0C0;</xsl:attribute>
        </xsl:if>
        <xsl:apply-templates select="@*|*" />
    </td>
</xsl:template>
.............

rgds,
Conor.
0
 
LVL 4

Author Comment

by:leslynf
ID: 11746198
Exactly where am I placing this code? I tried it in several different places -- no luck!

Leslyn :)
0
 
LVL 5

Expert Comment

by:conorj
ID: 11750643
Leslyn,

Where exactly have you tried it??

rgds,
Conor.
0
 
LVL 4

Author Comment

by:leslynf
ID: 11755851
Thanks for your info Conor; however, I resolved it in a different manner.

For other's information, the solution I used is as follows:

<TD ALIGN="right">
    <xsl:if test="Value = 0">
        <xsl:attribute name="style">background-color:#EEEEEE;</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="format-number(Value , '###,###,###,##0')"/>
</TD>
<TD ALIGN="right">
    <xsl:if test="Schools = 0">
        <xsl:attribute name="style">background-color:#EEEEEE;</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="format-number(Schools , '###,###,###,##0')"/>
</TD>
<TD ALIGN="right">
    <xsl:if test="Teachers = 0">
        <xsl:attribute name="style">background-color:#EEEEEE;</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="format-number(Teachers , '###,###,###,##0')"/>
</TD>
<TD ALIGN="right">
    <xsl:if test="Students = 0">
        <xsl:attribute name="style">background-color:#EEEEEE;</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="format-number(Students , '###,###,###,##0')"/>
</TD>
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

622 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