Copied to clipboard

Flag this post as spam?

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


  • jacob phillips 130 posts 372 karma points
    Feb 15, 2011 @ 22:30
    jacob phillips
    0

    XSLT SORT, RSS

    Hi,

    I'm just trying to sort my RSS list. I've tried several ways to sort after my for-each and also within apply-templates.

    The first sort is on updateDate to get the newest update date. Maybe that is affecting the later sort? (I've tried it w/o no sort after the first one).

    I must be getting the syntax wrong or not understand the context because it doesn't make any difference, I get get the sort order to change. My only parameter in this case is ?t=news:

    I've tried the following sorts after the for-each area and apply templates:

     


    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:ps="urn:percipientstudios-com:xslt"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:umbraco.contour="urn:umbraco.contour" xmlns:Designit.VideoEmbed="urn:Designit.VideoEmbed" xmlns:autofolders.library="urn:autofolders.library"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets umbraco.contour Designit.VideoEmbed autofolders.library ">


    <xsl:include href="cprGetPrimaryImage.xslt" />

    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    <!-- params passed via querystring: p=the page/world name (assigned to "pageName"),
    t=the one word title of the feed (assigned to "feedTitle"),
    n=the number of recent stories to show in the feed (assigned to "feedNumItems") -->
    <xsl:variable name="pageName">
    <xsl:choose>
    <xsl:when test="string-length(umbraco.library:Request('p')) &gt; 0">
    <xsl:text>cprFeatures</xsl:text>
    <xsl:value-of select="string(umbraco.library:Request('p'))" />
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="''" />
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

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

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

    <xsl:variable name="feedTitle">
    <xsl:choose>
    <xsl:when test="string-length($feedType) &gt; 0">
    <xsl:value-of select="'RSS Feed: '"/>
    <xsl:if test="$feedType = 'news'">Capital Public Radio News</xsl:if>
    <xsl:value-of select="umbraco.library:GetXmlNodeById($parentId)/@nodeName" />
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="'All Items'" />
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>
    <xsl:variable name="feedNumItems">
    <xsl:choose>
    <xsl:when test="string-length(umbraco.library:Request('n')) &gt; 0">
    <xsl:value-of select="string(umbraco.library:Request('n'))" />
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="'10'" />
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <xsl:variable name="parentNodeImage">
    <xsl:choose>
    <xsl:when test="$parentId &gt; 0">
    <xsl:call-template name="getprimaryimageurl"><xsl:with-param name="nodeid" select="$parentId" /></xsl:call-template>
    </xsl:when>
    <xsl:otherwise>&nbsp;</xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <xsl:variable name="SiteURL" select="concat(' http://',string(umbraco.library:RequestServerVariables('HTTP_HOST')))"/>

    <!-- takes querystring keyword parameters and construct description -->

    <xsl:variable name="feedDescription">
    <xsl:value-of select="'Stories related to '"/>
    <xsl:value-of select="$feedTitle" />
    </xsl:variable>

    <!-- 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">

    <xsl:sort select="@updateDate" data-type="text" order="descending" />

    <xsl:if test="position() = 1">
    <xsl:value-of select="umbraco.library:FormatDateTime(@updateDate,'r')" />
    </xsl:if>
    </xsl:for-each>
    </xsl:variable>

    <xsl:template match="/">
    <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/">
    <!-- sets up the header for the feed -->
    <channel>
    <title>
    <xsl:value-of select="$feedTitle"/>
    </title>
    <image>
    <url>http://capradio.org/images/logo250px.png</url>;
    <title>Capital Public Radio</title>
    <link>http://capradio.org</link>;
    </image>
    <link>
    <xsl:value-of select="$SiteURL"/>
    </link>
    <pubDate>
    <xsl:value-of select="$pubDate"/>
    </pubDate>
    <generator>umbraco</generator>
    <description>
    <xsl:value-of select="$feedDescription"/>
    </description>
    <language>en</language>


    <!-- find out which feed to serve based on querystring parameter -->
    <!-- if the feed parameter (keyword) is passed, use nodes where the keyword field contains the keyword parameter -->
    <!-- if no feed (keyword) parameter is passed, then show rss from all nodes -->

    <xsl:variable name="nodes" select="ps:GetRss(umbraco.library:Request('t'), $parentId)" />
    <xsl:if test="$nodes != ''">
    <xsl:variable name="splitNodes" select="umbraco.library:Split($nodes, ',')" />
    <xsl:for-each select="$splitNodes/value">
    <xsl:variable name="currentNode" select="umbraco.library:GetXmlNodeById(.)" />
    <xsl:if test="$currentNode/@id != '' ">
    <xsl:apply-templates select="$currentNode">

    <xsl:sort select="data [@alias = 'displayDate']" order="descending"/>
    </xsl:apply-templates>
    </xsl:if>
    </xsl:for-each>
    </xsl:if>

    </channel>
    </rss>

    </xsl:template>

    <xsl:template match="node">
    <xsl:if test="position() &lt;= $feedNumItems">
    <item>
    <title>
    <xsl:value-of select="@nodeName"/>
    </title>
    <description>
    <xsl:value-of select="data [@alias = 'teaser']" />
    </description>
    <link>
    <xsl:value-of select="$SiteURL"/>
    <xsl:value-of select="umbraco.library:NiceUrl(@id)"/>
    </link>
    <pubDate>
    <xsl:value-of select="umbraco.library:FormatDateTime(./data [@alias='displayDate'],'r')" />

    </pubDate>
    <guid>
    <xsl:value-of select="$SiteURL"/>
    <xsl:value-of select="umbraco.library:NiceUrl(@id)"/>
    </guid>
    <xsl:variable name="nodeimg"><xsl:call-template name="getprimaryimageurl"><xsl:with-param name="nodeid" select="@id" /></xsl:call-template></xsl:variable>
    <xsl:if test="$nodeimg != '' and $nodeimg != '&nbsp;'">
    <enclosure>
    <xsl:attribute name="url">http://www.capradio.org<xsl:value-of select="$nodeimg" /></xsl:attribute>
    <xsl:attribute name="type">image/jpeg</xsl:attribute>
    </enclosure>
    </xsl:if>
    <content:encoded>

    <xsl:value-of select="concat('&lt;![CDATA[ ', ./data [@alias='teaser'],']]&gt;')" disable-output-escaping="yes"/>
    </content:encoded>
    </item>
    </xsl:if>
    </xsl:template>

    <xsl:template name="getprimaryimageurl">
    <xsl:param name="nodeid"/>

    <xsl:variable name="relations" select="ps:GetRelatedNodes($nodeid, 'PrimaryImage')"/>

    <xsl:for-each select="$relations">
    <xsl:choose>
    <xsl:when test="node() and relations/relation/node/@id != ''"><xsl:value-of select="umbraco.library:GetMedia($relations/relations/relation/node/@id, 'false')/data [@alias = 'umbracoFile']" /></xsl:when>
    <xsl:otherwise>&nbsp;</xsl:otherwise>
    </xsl:choose>
    </xsl:for-each>

    </xsl:template>
    </xsl:stylesheet>
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies