Re: [xsl] alternate backgrounds problem...

Subject: Re: [xsl] alternate backgrounds problem...
From: Josh Canfield <joshcanfield@xxxxxxxxx>
Date: Tue, 22 Jun 2004 10:21:29 -0700
You can use position() and mod on a per portlet basis because you are
calling apply-templates with a union of all the section and link
nodes.

If you named your styles using the convention back-white-0 and back-white-1

   <xsl:template match="link">
       <xsl:variable name="colour" select="../@colour"/>
       <xsl:variable name="desclength" select="string-length(../description)"/>
       <div class="back-{$colour}-{position() mod 2}">
           LINK CONTENT
       </div>
   </xsl:template>

Josh

On Tue, 22 Jun 2004 13:41:49 +0100, james walker
<jameswalkerandy@xxxxxxxxxxx> wrote:
> 
> i am creating portlets for a webpage, each portlet has any number of
> "section" divs and "link" divs in any order. I am trying to create alternate
> background colours on these divs by using the xsl. For example, for a white
> portlet, i would want:
> 
> link div - no background (white)
> section div - grey background
> section div - no background
> link div - grey background
> etc.......
> 
> I think i may have to do something with parameter passing but not sure how
> to tackle it. I thought about maybe counting the number of divs in each
> portlet and then saying for every even numbered div have no background and
> every odd numbered div have a coloured background. However, i dont think you
> can figure out which divs would be odd and which would be even? My xml and
> xsl is below:
> 
> I have an xml file like this:
> 
> <page>
>    <portlet colour="white">
>    <link>
>        <name></name>
>    </link>
>   <link>
>        <name></name>
>    </link>
>   <section>
>        <name></name>
>    </section>
>    .......any number of mixed sections and links
>    </portlets>
>   <portlet colour="blue">
>    <link>
>        <name></name>
>    </link>
>   <link>
>        <name></name>
>    </link>
>   <section>
>        <name></name>
>    </section>
>    .......any number of mixed sections and links
>    </portlets>
> </page>
> 
> part of my xsl file looks a bit like this:
> <xsl:template match="portlet">
>        <xsl:variable name="colour" select="@colour" />
>        <div class="portlet-content" id="ne-portlet-content">
>                <!-- place description in portlet -->
>                <xsl:if test="string-length(description) != 0">
>                        <div class="back-none">
>                        <p><xsl:apply-templates select="description" /></p>
>                                </div>
>                </xsl:if>
>                <!-- place links/sections in portlet -->
>                <xsl:apply-templates select="link | section"/> <!-- linkc |
> section-->
>        </div>
>    </xsl:template>
> 
>    <xsl:template match="link">
>        <xsl:variable name="colour" select="../@colour"/>
>        <xsl:variable name="desclength"
> select="string-length(../description)"/>
>                <div class="back-{$colour}">
>                        LINK CONTENT
>                </div>
>    </xsl:template>
> 
>    <xsl:template match="section">
>        <xsl:variable name="colour" select="../@colour"/>
>        <xsl:variable name="desclength"
> select="string-length(../description)"/>
>        <div class="back-{$colour}">
>                SECTION CONTENT
>        </div>
>    </xsl:template>
> 
> _________________________________________________________________
> It's fast, it's easy and it's free. Get MSN Messenger today!
> http://www.msn.co.uk/messenger
> 
> --+------------------------------------------------------------------
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
> --+--
> 
>

Current Thread