Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDNN Open Source...DNN Open Source...Module ForumsModule ForumsNews FeedsNews FeedsChanging Background color to each articleChanging Background color to each article
Previous
 
Next
New Post
3/25/2009 10:37 AM
 

I would like to change the background color for each article listed in my feed.  Just like how these forums seperate the threads. Thanks for any help

 

  <?xml version="1.0" ?>
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" indent="yes" />
  <xsl:param name="ItemsToShow" />
  <xsl:param name="ShowItemDetails" />
  <xsl:param name="ShowItemDate" />
  <xsl:param name="Locale" />
- <xsl:template match="rss">
- <xsl:for-each select="channel/item[position()<=$ItemsToShow or $ItemsToShow<1]">
- <p class="DNN_News_ItemLink">
- <a href="{link}" target="_blank">
  <xsl:value-of select="title" />
  </a>
  </p>
- <xsl:if test="$ShowItemDate='true'">
- <p class="DNN_News_ItemDate">
  <xsl:value-of select="pubDate" />
  </p>
  </xsl:if>
- <xsl:if test="$ShowItemDetails='true'">
- <p class="DNN_News_ItemDetails">
  <xsl:value-of select="description" disable-output-escaping="yes" />
  </p>
  </xsl:if>
  </xsl:for-each>
  </xsl:template>
  </xsl:stylesheet>
 
New Post
3/25/2009 12:00 PM
 

I've put an example of doing this type of task on my blog, which you can view here.  The key part is including your item elements in a div tag, and this little snippet of xsl, after the div tag and in the area where you are getting your feed items:

   <xsl:if test="position() mod 2 != 0">
    <xsl:attribute  name="style">background-color: #F5F5F5</xsl:attribute>
  </xsl:if>

The example on my blog shows the entire xsl.

 
New Post
3/25/2009 2:50 PM
 

Thank you kind SIr,

 This helped alot and really makes the feed look alot better.

I have never dealt with XSL before, could you try to explain why that little bit of code does that? I'm having a hard time following it.

 
New Post
3/25/2009 3:52 PM
 

Sure, no problem. Basically, we are testing the item number's position in the list, which counts from 1 to see if we need to change the background color.  It works like this:

  <xsl:if test="position() mod 2 != 0">
    <xsl:attribute  name="style">background-color: #F5F5F5</xsl:attribute>
  </xsl:if>
 

The first time through, 1 mod 2 = 1, so the color of the background is changed.
The second time, 2 mod 2 = 0, so the test fails and the default color is used.
Third time through, 3 mod 2 = 1, the color of the background is changed.
Fourth time, 4 mod 2 = 0, so the test fails and the default color is used.

and so on...

This results in the even numbered items to use the default color of the container used and the odd number items to use the alternate color.  You could vary the action by modifying the test to:

<xsl:if test="position() mod 2 = 0">
 

which would result in the odd number items to use the default container color background, and the even number items to use the alternate color.

You could further modify the snippet to include an additional test to specify another color be used for both.  Take a look at TopXML's site, or just google on XSL for some other possibilities.  DNN has a nice XML/XSL module that can be used easily to explore the possibilities, or take a look at the xSelerator xml/xsl editor application, which I mention in my blog on Useful Developer Tools.

 
New Post
3/25/2009 4:04 PM
 

cool, I get it now.

you were really helpful.

 
Previous
 
Next
HomeHomeDNN Open Source...DNN Open Source...Module ForumsModule ForumsNews FeedsNews FeedsChanging Background color to each articleChanging Background color to each article


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out