Tuesday, 15 September 2015

xslt - Sort XML by RFC-822 date format using XSL -



xslt - Sort XML by RFC-822 date format using XSL -

does know of way kind of sorting in xsl?

here's have far sorts day , ignores rest of date.

<xsl:apply-templates select="item"> <xsl:sort select="pubdate" data-type="text" order="descending"/> </xsl:apply-templates>

thanks quick responses guys. got me going in right direction. managed solve it! found useful link http://blog.mastykarz.nl/how-to-do-it-rss-aggregation-merging-multiple-xml-files-using-xslt/

i using xslt version 2.0. case using variable substitute in mmm months , sub-stringing date down.

solution

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" indent="yes"/> <xsl:variable name="months" select="'jan;feb;mar;apr;may;jun;jul;aug;sep;oct;nov;dec'"/> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()" /> </xsl:copy> </xsl:template> <xsl:template match="channel"> <xsl:copy> <xsl:apply-templates select="@*|node()[not(preceding-sibling::item) , not(self::item)]"/> <xsl:apply-templates select="item"> <!-- year --> <xsl:sort select="substring(pubdate, 13, 4)" order="descending" data-type="number"/> <!-- month --> <xsl:sort select="string-length(substring-before($months, substring(pubdate, 9, 3)))" order="descending" data-type="number"/> <!-- day --> <xsl:sort select="substring(pubdate, 6, 2)" order="descending" data-type="number"/> <!-- hr --> <xsl:sort select="substring(pubdate, 18, 2)" order="descending" data-type="number"/> </xsl:apply-templates> <xsl:apply-templates select="@*|node()[not(following-sibling::item) , not(self::item)]"/> </xsl:copy> </xsl:template>

xml xslt rfc822

No comments:

Post a Comment