Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>The following transformation</strong>:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:variable name="vrtfMonths"&gt; &lt;m name="Jan" num="01"/&gt; &lt;m name="Feb" num="02"/&gt; &lt;m name="Mar" num="03"/&gt; &lt;m name="Apr" num="04"/&gt; &lt;m name="May" num="05"/&gt; &lt;m name="Jun" num="06"/&gt; &lt;m name="Jul" num="07"/&gt; &lt;m name="Aug" num="08"/&gt; &lt;m name="Sep" num="09"/&gt; &lt;m name="Oct" num="10"/&gt; &lt;m name="Nov" num="11"/&gt; &lt;m name="Dec" num="12"/&gt; &lt;/xsl:variable&gt; &lt;xsl:variable name="vMonths" select= "document('')/*/xsl:variable [@name='vrtfMonths']/*" /&gt; &lt;xsl:template match="channel"&gt; &lt;xsl:for-each select="item"&gt; &lt;xsl:sort data-type="number" order="descending" select= "concat(substring(pubDate,13,4), $vMonths[@name = substring(current()/pubDate,9,3)]/@num, substring(pubDate,6,2), translate(substring(pubDate,18,8), ':', '' ) ) "/&gt; &lt;xsl:if test="not(position() &gt; 5)"&gt; &lt;xsl:copy-of select="."/&gt; &lt;/xsl:if&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when applied on the provided source XML document (too-long to list here, see the <a href="http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/business/rss.xml" rel="noreferrer">link</a>)</strong>,</p> <p><strong>produces the wanted result</strong>:</p> <pre><code>&lt;item xmlns:media="http://search.yahoo.com/mrss"&gt; &lt;title&gt;Inflation rate expected to fall&lt;/title&gt; &lt;description&gt;The latest figures for the rate of inflation, for the 12 months to January, are expected to show that it has fallen again.&lt;/description&gt; &lt;link&gt;http://news.bbc.co.uk/go/rss/-/1/hi/business/7893873.stm&lt;/link&gt; &lt;guid isPermaLink="false"&gt;http://news.bbc.co.uk/1/hi/business/7893873.stm&lt;/guid&gt; &lt;pubDate&gt;Tue, 17 Feb 2009 02:58:03 GMT&lt;/pubDate&gt; &lt;category&gt;Business&lt;/category&gt; &lt;media:thumbnail width="66" height="49" url="http://newsimg.bbc.co.uk/media/images/45483000/jpg/_45483998_cash226.jpg" /&gt; &lt;/item&gt;&lt;item xmlns:media="http://search.yahoo.com/mrss"&gt; &lt;title&gt;Farming pressures&lt;/title&gt; &lt;description&gt;Are farmers being forced to use GM seeds?&lt;/description&gt; &lt;link&gt;http://news.bbc.co.uk/go/rss/-/1/hi/business/7892328.stm&lt;/link&gt; &lt;guid isPermaLink="false"&gt;http://news.bbc.co.uk/1/hi/business/7892328.stm&lt;/guid&gt; &lt;pubDate&gt;Tue, 17 Feb 2009 00:06:31 GMT&lt;/pubDate&gt; &lt;category&gt;Business&lt;/category&gt; &lt;media:thumbnail width="66" height="49" url="http://newsimg.bbc.co.uk/media/images/45481000/jpg/_45481936_005666785-1.jpg" /&gt; &lt;/item&gt;&lt;item xmlns:media="http://search.yahoo.com/mrss"&gt; &lt;title&gt;Engine room?&lt;/title&gt; &lt;description&gt;Western Australia's economy may be hitting reverse. &lt;/description&gt; &lt;link&gt;http://news.bbc.co.uk/go/rss/-/1/hi/business/7840370.stm&lt;/link&gt; &lt;guid isPermaLink="false"&gt;http://news.bbc.co.uk/1/hi/business/7840370.stm&lt;/guid&gt; &lt;pubDate&gt;Tue, 17 Feb 2009 00:05:25 GMT&lt;/pubDate&gt; &lt;category&gt;Business&lt;/category&gt; &lt;/item&gt;&lt;item xmlns:media="http://search.yahoo.com/mrss"&gt; &lt;title&gt;Coining it in? &lt;/title&gt; &lt;description&gt;Investors turning to old and rare coins in the downturn &lt;/description&gt; &lt;link&gt;http://news.bbc.co.uk/go/rss/-/1/hi/business/7878606.stm&lt;/link&gt; &lt;guid isPermaLink="false"&gt;http://news.bbc.co.uk/1/hi/business/7878606.stm&lt;/guid&gt; &lt;pubDate&gt;Tue, 17 Feb 2009 00:04:29 GMT&lt;/pubDate&gt; &lt;category&gt;Business&lt;/category&gt; &lt;media:thumbnail width="66" height="49" url="http://newsimg.bbc.co.uk/media/images/45459000/jpg/_45459789_dsc_4982.jpg" /&gt; &lt;/item&gt;&lt;item xmlns:media="http://search.yahoo.com/mrss"&gt; &lt;title&gt;Home sales may rise say surveyors&lt;/title&gt; &lt;description&gt;Property sales may pick in the next few months, according to the Royal Institution of Chartered Surveyors (Rics).&lt;/description&gt; &lt;link&gt;http://news.bbc.co.uk/go/rss/-/1/hi/business/7893193.stm&lt;/link&gt; &lt;guid isPermaLink="false"&gt;http://news.bbc.co.uk/1/hi/business/7893193.stm&lt;/guid&gt; &lt;pubDate&gt;Tue, 17 Feb 2009 00:02:19 GMT&lt;/pubDate&gt; &lt;category&gt;Business&lt;/category&gt; &lt;media:thumbnail width="66" height="49" url="http://newsimg.bbc.co.uk/media/images/45483000/jpg/_45483075_006771638-1.jpg" /&gt; &lt;/item&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload