If all your pubDate
's do not have the weekday you would simply substract 5 from each substring starting point in the sort statement:
<xsl:sort data-type="number" order="descending" select=
"concat(substring(pubDate,8,4),
$vMonths[@name
=
substring(current()/pubDate,4,3)]/@num,
substring(pubDate,1,2),
translate(substring(pubDate,13,8),
':',
''
)
)
"/>
However if you have a mix of pubDate formats, and you have both:
<pubDate>12 Feb 2009 01:58:03 GMT</pubDate>
<pubDate>Tue, 13 Feb 2010 02:58:03 GMT</pubDate>
The starting points of the substring expressions needs to be conditional depending on your format.
In XSLT 2.0 you could simply use an xpath if then else
statement like:
substring(pubDate, if (substring(pubDate,3,1)=' ') then 8 else 13 ,4)
This checks if there is a blank space at char 3, which is the case for the format without the weekday but not for the format with the weekday, and sets the substring starting point according.
In XSLT 1.0 there is no conditional expression within an xpath, but you can get the same result by multiplying with the result of a boolean expression:
substring(pubDate,
(substring(pubDate,3,1)=' ') * 8 + (substring(pubDate,5,1)=' ') * 13
,4)
This will calculate 1 * 8 + 0 * 13 = 8
for the format without the weekday and vice versa 0 * 8 + 1 * 13 = 13
for the format with weekday.
Doing this for the whole sort statement:
<xsl:sort data-type="number" order="descending" select=
"concat(substring(pubDate,
(substring(pubDate,3,1)=' ') * 8 + (substring(pubDate,5,1)=' ') * 13
,4),
$vMonths[@name =
substring(current()/pubDate,
(substring(pubDate,3,1)=' ') * 4 + (substring(pubDate,5,1)=' ') * 9
,3)]/@num,
substring(pubDate,
(substring(pubDate,3,1)=' ') * 1 + (substring(pubDate,5,1)=' ') * 6
,2),
translate(
substring(pubDate,13
(substring(pubDate,3,1)=' ') * 13 + (substring(pubDate,5,1)=' ') * 18
,8),
':',
''
)
)
"/>
Here is a working simplified version: http://xsltransform.net/jyyiVhv
As for your second question, In addition it would be convenient to know how to implement an additional RSS-node to sort on like or . The resulting output for example would be sorted on and (or eg. ).
You usually would simply add <xsl:sort select="title"/>
however considering the previous sorting by date, this would only happen if you would have 2 different title's on the exact same pubdate, which is rather impossible since the date also includes time.