Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-08-08
5
Medium Priority
?
1,431 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 1500 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 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