The awkward thing about RSS is the date format (rfc 822), it makes sorting a 
bit tricky. One way of simplifying sorting is to loop over the <item> tags and 
build a new nodeset with an extra unix-time or iso-time tag to represent the 
pubDate in a more sort-friendly format.

If you fetch the RSS feed using rxml:s insert-href or insert-cached-href tags 
it might be preferable to add the unix-timestamp in rxml instead of in xslt 
(since Roxens xslt-parser as far as I know don't have any time functions and 
you probably don't want to invoke several xsltransform passes)


Here is one way of doing the unix-time replacement in rxml:
----

<?comment ### define a tag "rss" to parse a RSS feed ### ?>
<define container="rss">
    <?comment ## defines to build new item-nodeset with a unix-timestamp ## ?>
    <define container="newNode">
        <append variable="var.newNodeSet" type="text/xml">
            <item>
                <contents copy-of="item/*"/>
                <set variable="_.pubDate"><contents 
value-of="item/pubDate"/></set>
                <unixtime><date http-time="&_.pubDate;" type="unix" 
/></unixtime>
            </item>
        </append>
    </define>
    
    <define container="timeParser">
        <set variable='_.feeditems'><contents copy-of="rss/channel/item" 
result-set=""/></set>
        <?comment ## loop over item:s and call newNode for each one ## ?>
        <emit source='values' variable='_.feeditems'>
            <newNode>&_.value:none;</newNode>
        </emit>
    </define>
    
    <?comment ### ger rss-feed from url or cached in db and pass it to 
timeParser define ## ?>
    <timeParser><insert cached-href="&_.feed;" quote="none" /></timeParser>    
    
    <?comment ## the new nodeset is now available in the variable 
var.newNodeSet ## ?>
    &var.newNodeSet:none;
</define>

<rss feed="http://feeds.bbci.co.uk/news/rss.xml"; />

----


If you want to transform the new feed-nodeset with xslt you can now do:

<xsltransform xsl="yourxsl.xsl" 
preparse="yes"><newNodeSet>&rss.newNodeSet:none;</newNodeSet></xsltransform>

and in that templatefile have something like:
<xsl:template match="newNodeSet">
    <xsl:for-each select="//item">
      <xsl:sort select="unixtime" data-type="number"/>
      <h3><xsl:value-of select="title"/></h3>
      <p>
        <xsl:value-of select="pubDate" />, <xsl:value-of select="description" />
      </p>
    </xsl:for-each>
</xsl:template>


Haven't tested the xsl-parts but the rxml should work. Hope this helps

/Peter





>________________________________
> From: Christopher Howard <[email protected]>
>To: Roxen <[email protected]> 
>Sent: Wednesday, August 7, 2013 9:15 PM
>Subject: Roxen xslt and date filtering
> 
>
>Hi. I'm still an XSLT newbie, but I am trying to use some XSLT in Roxen 
>to transform an RSS feed into html. However, I want to do filtering 
>based on the date, e.g., only display five entries with the most recent 
>pubDate. Working from within a Roxen system, what are my options for 
>date sorting/filtering?
>
>
>

Reply via email to