[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Changing row colors using variables

Subject: Re: Changing row colors using variables
From: Jörg Heinicke <joerg.heinicke@xxxxxx>
Date: Thu, 8 Nov 2001 02:11:36 +0100
xsl row color
Hi Steve,

the only problem I see is: Where do you get $currentRowColor from? Was this
in your code too? Then this won't work ... as David already said. The
problem: You won't get a variable value from using a template once to the
template using it the 2nd time (with easy <xsl:apply-templates
select="row"/>). One method would be using recursive template: Apply always
only the next following-sibling one. So:

<xsl:template match="table">
    <table>
        <xsl:apply-templates select="row[1]"/>
    </table>
</xsl:template>

<xsl:template match="row">
    <xsl:param name="color-of-last-row"/>
    <xsl:variable name="color-of-this-row">
        <xsl:choose>
            <xsl:when test="@t_orno != preceding-sibling::row[1]/@t_orno">
                <xsl:choose>
                    <xsl:when test="$color-of-last-row='#EFFFFF'">
                        <xsl:text>#FFFFFF</xsl:text>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:text>#EFFFFF</xsl:text>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$color-of-last-row"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <tr bgcolor="{$color-of-this-row}">
        <!-- filling the <tr> with some <td>s -->
    </tr>
    <xsl:apply-templates select="following-sibling::row[1]">
        <!-- give the $color-of-this-row as color-of-last-row to the next
row -->
        <xsl:with-param name="color-of-last-row" select="$color-of
this-row"/>
    </xsl:apply-templates>
</xsl:template>

This should solve the problem - if this is the problem you had.

Regards,

Joerg


> <xsl:attribute name="bgcolor">
> <xsl:if test="@t_orno != preceding-sibling::row[1]/@t_orno">
> <xsl:choose>
> <xsl:when test="$currentRowColor='#EFFFFF'">
> $currentRowColor=#FFFFFF
> </xsl:when>
> <xsl:otherwise>
> $currentRowColor=#EFFFFF
> </xsl:otherwise>
> </xsl:choose>
> </xsl:if>
> <xsl:value-of select="$currentRowColor"/>
> </xsl:attribute>
>
>
> I have a variable name currentRowColor...if the value of t_orno is not the
> same as t_orno in the preceding row, I want to switch row colors in my
> grid...that way all rows of the same "t_orno" field will be colored
> together. This code acts funny though, depending on where I put single
> quotes...if I don't put the single quotes around #EFFFFF in the test
> statement, it does not work...adding quotes around the variable assignment
> like so: $currentRowColor='#EFFFFF' changes the color. I don't think I am
> assigning the variables correctly, because the test condition does not
> always work correctly.
>
> --Steve Kuntz


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.