xml - How to use XSLT to group RSS feeds -
i have xml file data read feeds on internet. xml standard rss 2.0 file. looks (i ommited tags shorten post):
<?xml version="1.0" encoding="iso-8859-1"?> <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"> <channel> <title/> <item> <title>blah</title> <category>cat1</category> </item> <item> <title>blah2</title> <category>cat2</category> </item> <item> <title>blah3</title> <category>cat1</category> </item> </channel> </rss>
what i'm trying use xslt create html file. problem need group items category tag. in order generate like:
<div> <span>cat1</span> <div> <span>blah</span> <span>blah3</span> </div> </div> <div> <span>cat2</span> <div> <span>blah2</span> </div> </div>
so far found bunch os posts teaches how use xslt group using attributes (like this, this , this). but, attempts adaptate failed.
tia,
bob
this should started
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" > <xsl:output method="html" indent="yes" omit-xml-declaration="yes"/> <xsl:template match="@* | node()"> <xsl:apply-templates select="@* | node()"/> </xsl:template> <xsl:template match="item[not(category = preceding-sibling::item/category)]"> <xsl:variable name="category" select="category"/> <div> <span> <xsl:value-of select="category"/> </span> <div> <span> <xsl:value-of select="title"/> </span> <xsl:apply-templates select="following-sibling::item[category=$category]" mode="extra"/> </div> </div> </xsl:template> <xsl:template match="item" mode="extra"> <span> <xsl:value-of select="title"/> </span> </xsl:template> </xsl:stylesheet>
Comments
Post a Comment