Solved

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

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

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
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 video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 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

12 Experts available now in Live!

Get 1:1 Help Now