Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Chris Cully 1 post 21 karma points
    Feb 09, 2010 @ 17:22
    Chris Cully
    0

    Help with RSS, xslt, and aspx parameters

    Hi all,

    Sorry if this question has been asked before; when i search the forum, i didnt find anything that helped.

    I have already implemented an RSS feed to iterate over a number of pages in my site, and generate a feed based on page data, which seems to work fine.

    I now need to add two more feeds; one that filters the projects by Tag, and on the filters by Title. I would like to enable users to specify the filter criteria in the URL. For instance, i would like to have the tag-filter rss page accessed by the following URL...

    http://<serverName>/projects/rss.aspx?tag=<tagName>,

    ...and then in the RSS xslt, access the tag parameter string so that i can discover the string to filter by. I can then iterate through the pages and pull the data for related pages into the RSS. This bit i know how to do; it's accessing the parameter content that has me really stumped.

    Is this possible to do, and if so, would anyone be able to point out an article i can use to figure out how to do this. I'm completely stumped on this at the moment, and am spinning in circles not getting anywhere...

    Thanks in advance to anyone that can help.

  • dandrayne 1138 posts 2262 karma points
    Feb 09, 2010 @ 17:29
    dandrayne
    0

    It's possible, and here is the xslt that we use for exactly that.  Post back if you'd like any particular part of it explained

    examples:  http://www.geckonewmedia.com/blog/rss?filterby=umbraco and http://www.geckonewmedia.com/blog/rss?filterby=jquery

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    xmlns:tagsLib="urn:tagsLib"
    xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings"
    xmlns:rssdatehelper="urn:rssdatehelper"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    exclude-result-prefixes="msxml umbraco.library tagsLib Exslt.ExsltStrings">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <!-- Update these variables to modify the feed -->
    <xsl:variable name="RSSNoItems" select="string('10')"/>
    <xsl:variable name="RSSTitle" select="$currentPage/data [@alias = 'blogName']"/>
    <xsl:variable name="SiteURL" select="string('http://www.geckonewmedia.com')"/>
    <xsl:variable name="RSSDescription" select="$currentPage/data [@alias = 'blogDescription']"/>

    <!-- This gets all news and events and orders by updateDate to use for the pubDate in RSS feed -->
    <xsl:variable name="pubDate">
    <xsl:for-each select="$currentPage//node [@alias = 'BlogPost']">
    <xsl:sort select="@createDate" data-type="text" order="descending" />
    <xsl:if test="position() = 1">
    <xsl:value-of select="updateDate" />
    </xsl:if>
    </xsl:for-each>
    </xsl:variable>

    <xsl:variable name="filter">
    <xsl:choose>
    <xsl:when test="string-length(umbraco.library:Request('filterby')) &gt; 0">
    <xsl:value-of select="umbraco.library:Request('filterby')"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="''"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <xsl:template match="/">
    <!-- change the mimetype for the current page to xml -->
    <xsl:value-of select="umbraco.library:ChangeContentType('text/xml')"/>

    <xsl:text disable-output-escaping="yes">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</xsl:text>
    <rss version="2.0"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:wfw="http://wellformedweb.org/CommentAPI/"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    >

    <channel>
    <title>
    <xsl:value-of select="$RSSTitle"/>
    </title>
    <link>
    <xsl:value-of select="$SiteURL"/>
    </link>
    <pubDate>
    <xsl:value-of select="$pubDate"/>
    </pubDate>
    <generator>umbraco</generator>
    <description>
    <xsl:value-of select="$RSSDescription"/>
    </description>
    <language>en</language>
    <xsl:choose>
    <xsl:when test="$filter = ''">
    <xsl:apply-templates select="$currentPage//node [@nodeTypeAlias = 'BlogPost']">
    <xsl:sort select="@createDate" order="descending" />
    </xsl:apply-templates>
    </xsl:when>
    <xsl:otherwise>
    <xsl:apply-templates select="$currentPage//node [@nodeTypeAlias = 'BlogPost' and contains(Exslt.ExsltStrings:lowercase(./data [@alias='tags']), Exslt.ExsltStrings:lowercase($filter))]">
    <xsl:sort select="@createDate" order="descending" />
    </xsl:apply-templates>
    </xsl:otherwise>
    </xsl:choose>
    </channel>
    </rss>

    </xsl:template>

    <xsl:template match="node">
    <xsl:if test="position() &lt;= $RSSNoItems">
    <item>
    <title>
    <xsl:value-of select="@nodeName"/>
    </title>
    <link>
    <xsl:value-of select="$SiteURL"/>
    <xsl:value-of select="umbraco.library:NiceUrl(@id)"/>
    </link>
    <pubDate>
    <xsl:value-of select="umbraco.library:FormatDateTime(@createDate,'r')" />
    </pubDate>
    <guid>
    <xsl:value-of select="$SiteURL"/>
    <xsl:value-of select="umbraco.library:NiceUrl(@id)"/>
    </guid>
    <content:encoded>
    <xsl:value-of select="concat('&lt;![CDATA[ ', ./data [@alias='blogSummary'],']]&gt;')" disable-output-escaping="yes"/>
    </content:encoded>
    </item>
    </xsl:if>
    </xsl:template>

    </xsl:stylesheet>

    Hope this helps,

    Dan

Please Sign in or register to post replies

Write your reply to:

Draft