RE: [xsl] xsl:if statement with numeric

Subject: RE: [xsl] xsl:if statement with numeric
From: "Kenny Akridge" <kenny@xxxxxxxxxxxxxxxxx>
Date: Sun, 28 Mar 2004 03:13:10 -0500
I'm not exactly sure in what context you want to use this solution, but the
solution you have is very rigid.  If you were doing something like grades,
you would want to set it up like this:


<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
	<xsl:template match="monat">
		<table>
			<tr>
				<xsl:apply-templates/>
			</tr>
		</table>
	</xsl:template>
	<xsl:template match="td">
		<xsl:element name="td">
			<xsl:attribute name="style">
			<xsl:text>background-color:</xsl:text>
				<xsl:choose>
					<xsl:when test="number(.) &gt;
90.00">
						<xsl:text>#9990AA</xsl:text>
					</xsl:when>
					<xsl:when test="number(.) &gt;
80.00">
						<xsl:text>#B0C0BB</xsl:text>
					</xsl:when>
					<xsl:when test="number(.) &gt;
70.00">
						<xsl:text>#C0E0CC</xsl:text>
					</xsl:when>
					<xsl:when test="number(.) &gt;
60.00">
						<xsl:text>#D700DD</xsl:text>
					</xsl:when>
					<xsl:otherwise>
						<xsl:text>#E099EE</xsl:text>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:attribute>
			<xsl:value-of select="."/>
		</xsl:element>
	</xsl:template>
</xsl:stylesheet>
-----Original Message-----
From: Tuan Luu [mailto:tuanluu@xxxxxx] 
Sent: Sunday, March 28, 2004 2:35 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] xsl:if statement with numeric

somehow I  did find a solution: 

        <xsl:choose>
            <xsl:when test= "number(.) = 100.00">
                <td bgcolor="#00ff00" align="right">
                    <xsl:apply-templates/>
                </td>
            </xsl:when>
            <xsl:when test= "number(.) &gt; 98.70">
                <td bgcolor="#ff0000" align="right">
                    <xsl:apply-templates/>
                </td>
            </xsl:when>
            <xsl:otherwise>
                <td bgcolor="#ff9600" align="right">
                    <xsl:apply-templates/>
                </td>
            </xsl:otherwise>
        </xsl:choose>


> hello 
> I'm very new to this. 
> I have an xml returned that looks like this: 
> 
> <td>100</td>
> <td>98.00</td>
> <td>100</td>
> 
> now I'd like to give the td tags different colors, depending on the value.
> What I did so far ist that: 
> 
> <xsl:template match="monat">
>         <xsl:if test= "numeric(.) &lt; 100.00">     
>             <xsl:variable name="farbe">#00ff00</xsl:variable>
>         </xsl:if>
>     <td bgcolor="$farbe" align="right">
>         <xsl:apply-templates/>
>     </td>
> </xsl:template>
> 
> My problem is, I think he doesn't make a difference with the value, all
> columns get the same color. 
> What have I done wrong here?
> Thanks for any answers.
> 
> -- 
> +++ NEU bei GMX und erstmalig in Deutschland: T\V-gepr|fter Virenschutz
> +++
> 100% Virenerkennung nach Wildlist. Infos: http://www.gmx.net/virenschutz
> 

-- 
+++ NEU bei GMX und erstmalig in Deutschland: T\V-gepr|fter Virenschutz +++
100% Virenerkennung nach Wildlist. Infos: http://www.gmx.net/virenschutz

Current Thread