locked
Shading Alternate Rows in an RSS Viewer Web Part in SharePoint RRS feed

  • Question

  • I am really surprised I cannot even find someone else asking this question on the web.

    I am using MOSS 2007. I have an RSS Viewer Web Part.  I want to make the alternating rows different colors.  With a SharePoint list, I can just set the Style property of the View to shading and I get a pretty blue background on every other row.  How can I do this with an RSS Viewer?



    Christopher W. Douglas
    Monday, March 9, 2009 11:38 AM

Answers

  • Hope this will do.



    ...
    ...
    ...
       <xsl:for-each select="$Rows">
                    <xsl:variable name="CurPosition" select="position()" />
                    <xsl:variable name="RssFeedLink" select="$rss_WebPartID" />
                    <xsl:variable name="CurrentElement" select="concat($RssFeedLink,$CurPosition)" />
                    <xsl:if test="($CurPosition &lt;= $rss_FeedLimit)">
                        <div>
           <xsl:attribute name="class">
            <xsl:if test="not(position() mod 2)">item link-item</xsl:if>
            <xsl:if test="position() mod 2">item link-item ms-alternating</xsl:if>
           </xsl:attribute>

          
    ...
    ...
    ...                         


    (remove class atribute from the div)



    Good luck

    Renee
    Monday, March 9, 2009 8:32 PM
  • Renee Hulsman said:

    Hope this will do.



    ...
    ...
    ...
       <xsl:for-each select="$Rows">
                    <xsl:variable name="CurPosition" select="position()" />
                    <xsl:variable name="RssFeedLink" select="$rss_WebPartID" />
                    <xsl:variable name="CurrentElement" select="concat($RssFeedLink,$CurPosition)" />
                    <xsl:if test="($CurPosition &lt;= $rss_FeedLimit)">
                        <div>
           <xsl:attribute name="class">
            <xsl:if test="not(position() mod 2)">item link-item</xsl:if>
            <xsl:if test="position() mod 2">item link-item ms-alternating</xsl:if>
           </xsl:attribute>

          
    ...
    ...
    ...                         


    (remove class atribute from the div)



    Good luck

    Renee



    Renee,

      Thank you so much!  I don't know how I misread it, but the class I wanted to emulate was ms-alternatingstrong, not ms-alternating.  Once I fixed that, it worked!  Incidentally, I can't find this class in the template, maybe it's in the master page, I don't know.  Anyway, your fix worked.  Now my RSS feeds alternate colors just like the other lists, hoorah!

    Thanks again!

    Christopher W. Douglas
    Tuesday, March 10, 2009 12:10 PM

All replies

  • Hi,

    You can edit the xslt of the RSS viewer in the webpart properties. 


    for example:

    .....
    .....
    .....
      <xsl:for-each select="$Rows">
                    <xsl:variable name="CurPosition" select="position()" />
                    <xsl:variable name="RssFeedLink" select="$rss_WebPartID" />
                    <xsl:variable name="CurrentElement" select="concat($RssFeedLink,$CurPosition)" />
                    <xsl:if test="($CurPosition &lt;= $rss_FeedLimit)">
                        <div class="item link-item" >
           <xsl:attribute name="style">
            <xsl:if test="position() mod 2">background-color: #C0C0C0;</xsl:if>
           </xsl:attribute>

           
    .....
    .....
    .....


    If you edit the RSS viewer in SharePoint Designer it is very easy to add diffrent colors to alternating rows and you can even do a lot of other (conditional)formating.

    If you need to know how to edit in SharePoint designer let me know...


    Renee
    • Proposed as answer by Renee Hulsman Monday, March 9, 2009 3:07 PM
    Monday, March 9, 2009 2:57 PM
  • Renee Hulsman said:

    Hi,

    You can edit the xslt of the RSS viewer in the webpart properties. 


    for example:

    .....
    .....
    .....
      <xsl:for-each select="$Rows">
                    <xsl:variable name="CurPosition" select="position()" />
                    <xsl:variable name="RssFeedLink" select="$rss_WebPartID" />
                    <xsl:variable name="CurrentElement" select="concat($RssFeedLink,$CurPosition)" />
                    <xsl:if test="($CurPosition &lt;= $rss_FeedLimit)">
                        <div class="item link-item" >
           <xsl:attribute name="style">
            <xsl:if test="position() mod 2">background-color: #C0C0C0;</xsl:if>
           </xsl:attribute>

           
    .....
    .....
    .....


    If you edit the RSS viewer in SharePoint Designer it is very easy to add diffrent colors to alternating rows and you can even do a lot of other (conditional)formating.

    If you need to know how to edit in SharePoint designer let me know...


    Renee



    Very good, but how do I apply a class instead of a style?  All of the lists use ms-alternating, and I have had a terrible time trying to find a shade of blue that matches ms-alernating's background color.  Can I apply the ms-alternating class to alternating rows, even though the class is "item link-item"?

     

     


    Christopher W. Douglas
    Monday, March 9, 2009 6:58 PM
  • Hope this will do.



    ...
    ...
    ...
       <xsl:for-each select="$Rows">
                    <xsl:variable name="CurPosition" select="position()" />
                    <xsl:variable name="RssFeedLink" select="$rss_WebPartID" />
                    <xsl:variable name="CurrentElement" select="concat($RssFeedLink,$CurPosition)" />
                    <xsl:if test="($CurPosition &lt;= $rss_FeedLimit)">
                        <div>
           <xsl:attribute name="class">
            <xsl:if test="not(position() mod 2)">item link-item</xsl:if>
            <xsl:if test="position() mod 2">item link-item ms-alternating</xsl:if>
           </xsl:attribute>

          
    ...
    ...
    ...                         


    (remove class atribute from the div)



    Good luck

    Renee
    Monday, March 9, 2009 8:32 PM
  • Renee Hulsman said:

    Hope this will do.



    ...
    ...
    ...
       <xsl:for-each select="$Rows">
                    <xsl:variable name="CurPosition" select="position()" />
                    <xsl:variable name="RssFeedLink" select="$rss_WebPartID" />
                    <xsl:variable name="CurrentElement" select="concat($RssFeedLink,$CurPosition)" />
                    <xsl:if test="($CurPosition &lt;= $rss_FeedLimit)">
                        <div>
           <xsl:attribute name="class">
            <xsl:if test="not(position() mod 2)">item link-item</xsl:if>
            <xsl:if test="position() mod 2">item link-item ms-alternating</xsl:if>
           </xsl:attribute>

          
    ...
    ...
    ...                         


    (remove class atribute from the div)



    Good luck

    Renee



    Renee,

      Thank you so much!  I don't know how I misread it, but the class I wanted to emulate was ms-alternatingstrong, not ms-alternating.  Once I fixed that, it worked!  Incidentally, I can't find this class in the template, maybe it's in the master page, I don't know.  Anyway, your fix worked.  Now my RSS feeds alternate colors just like the other lists, hoorah!

    Thanks again!

    Christopher W. Douglas
    Tuesday, March 10, 2009 12:10 PM