alternate backgrounds problem...

Subject: alternate backgrounds problem...
From: "james walker" <jameswalkerandy@xxxxxxxxxxx>
Date: Tue, 22 Jun 2004 13:41:49 +0100
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



Current Thread