Solved

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

Posted on 2004-08-08
5
1,422 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
  • 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Changing Sitemap Frequency on XML File 3 68
CRM 2011 Ribbon Workbench vs RibbonDiffXml 44 308
Help with SimpleXML charts with PHP 4 95
Test ddwrt:UserLookup 1 65
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…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

773 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