Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL Filtering on RSS Feed 1

Status
Not open for further replies.

danyeel

Programmer
Dec 9, 2008
6
Dear All

I have written a simple bit of XSL to take in a SharePoint RSS feed and display it on my website. I just need to add a condition to it because I only want it to display items where the "title" begins with the words "Theme of the week ".

Code:
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
<xsl:output method="html" />

<xsl:template match="/">

  <xsl:for-each select="rss/channel/item">

    <h3>
      <xsl:value-of select="title" />
    </h3>
    <p> Worship resources</p>
    <p class="footer">
      Theme for
      <xsl:value-of select="description" />
    </p>
  </xsl:for-each>

</xsl:template>

</xsl:stylesheet>

I'm convinced it should be easy but so far I've found it really difficult to modify - everything I've tried has meant it doesn't work.

If you can offer any advise I would be very grateful.

Thank you for your time
Lucie
 
Take good note on the nodes' namespaces in the rss.
 
Thanks tsuji but that is gibberish to me... I have no idea what you mean?!

Because the RSS is coming from SharePoint, I'm not sure how much control I have over the available namespaces.
 
Suppose those elements have no namespace, if the rss in question is of this form which normally could well be, it is this.
><xsl:for-each select="rss/channel/item">
[tt]<xsl:for-each select="rss/channel/item[blue][substring(title,1,18)='Theme of the week '][/blue]">[/tt]
 
Oh I see! Thank you, I'll have a look and let you know if it works.

Many thanks
 
Woo hoo, you're so clever! It works...

I'm afraid I have two more little questions though. At the moment it is showing all the RSS entries beginning with "Theme of the week" but I could do with it just showing the first one in the list.

And finally, I wondered if it is possible to remove the "Theme of the week" text from the output so if it is "Theme of the Week Christmas", it will just display "Christmas".

Do you think all this is possible? I really appreciate your help on this - you're very kind.
 
>...but I could do with it just showing the first one in the list.
[tt] <xsl:for-each select="rss/channel/item[substring(title,1,18)='Theme of the week '][blue][1][/blue]">[/tt]

>...if it is possible to remove the "Theme of the week" text from the output so if it is "Theme of the Week Christmas", it will just display "Christmas".
[tt] <xsl:value-of select="[blue]substring-after([/blue]title[blue],'Theme of the Week ')[/blue]" />[/tt]
 
You are an XSL genius! Thank you very much for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top