Subject: Re: [xsl] Grouping Problem - XML Repeating Elements w/out Attributes From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx> Date: Mon, 28 Jul 2008 22:36:03 +0530 |
I would suggest a bit of restructuring the logic. The key definition is different, and other logic too. Below is the pseudo code for this (not tested ...). <xsl:key name="cat_name" match="category" use="." /> <xsl:for-each select="//category[generate-id() = generate-id(key('cat_name',.)[1])]"> <xsl:value-of select="." /><br/> <xsl:for-each select="key('cat_name',.)"> <xsl:value-of select="../title" /><br/> </xsl:for-each> </xsl:for-each> On Mon, Jul 28, 2008 at 10:17 PM, Brent Solly <ultra@xxxxxxxxx> wrote: > <?xml version="1.0" encoding="UTF-8"?> > <rss> > <channel> > <generator>Systems</generator> > <item> > <title>Ogre Battle is sold out</title> > <description>There is a high demand for this > rare game.</description> > <category>SNES</category> > <category>SEGA</category> > </item> > <item> > <title>Final Fantasy 3 Breaks FF2 > Record</title> > <description>It was thought impossible to > outdo FF2 gameplay.</description> > <category>SNES</category> > </item> > <item> > <title>SNES is the Ultimate System</title> > <description>This new system has > revolutionized controller design.</description> > <category>SNES</category> > </item> > <item> > <title>Sonic The Hedgehog an instant > success</title> > <description>A new Mario is been > born.</description> > <category>SEGA Genesis</category> > </item> > <item> > <title>Joe Montanna Talking Football is > amazing</title> > <description>Listen play by play in this new > form of football game.</description> > <category>SEGA Genesis</category> > </item> > </channel> > </rss> > > > > > > <?xml version="1.0" encoding="UTF-8"?> > > <xsl:stylesheet > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="1.0"> > <xsl:strip-space elements="*" /> > <xsl:output method="html" encoding="UTF-8"/> > <xsl:key name="cat_name" match="item" use="category" > /> > > <!--Games --> > <xsl:template name="body" match="/"> > <xsl:choose> > <xsl:when test="rss/channel/generator = > 'Systems'"> > <!-- Generates Table of Contents with content links > --> > <xsl:apply-templates/> > > <br/><br/> > <!-- Description --> > > <xsl:for-each select="rss/channel/item"> > <xsl:variable name="link-path" > select="link"/> > <b class="abbott_hl2"><xsl:value-of > select="title"/></b><br/> > <xsl:if test="description!=''"> > <a name="{generate-id()}"/> > <xsl:value-of select="description" > /><xsl:text> </xsl:text><a href="{$link-path}" > target="_blank" class="abbott_storyurl">Click here for > fulltext</a><br/><br/> > > </xsl:if> > </xsl:for-each> > <!-- End Description --> > > </xsl:when> > > </xsl:choose> > </xsl:template> > > <!--Generates a unique id based on category name--> > <xsl:template match="channel"> > <xsl:apply-templates > select="item[generate-id(.) = > generate-id(key('cat_name', category)[1])]" /> > </xsl:template> > > <!--Outputs all titles relating to the category named > in each item--> > <xsl:template match="rss/channel/item"> > <b><xsl:value-of select="category" /></b> > <ul> > <xsl:for-each select="key('cat_name', category)"> > <li> > <a href="#{generate-id()}"> > <xsl:value-of select="title" /> > </a> > </li> > </xsl:for-each> > </ul> > </xsl:template> > > </xsl:stylesheet> > > Output Now > ----------- > SNES > Ogre Battle is sold out > Final Fantasy 3 Breaks FF2 Record > SNES is the Ultimate System > > > > SEGA Genesis > Sonic The Hedgehog an instant success > Joe Montanna Talking Football is amazing > > > Output Desired > > ----------------------- > > SNES > Ogre Battle is sold out <--- > Final Fantasy 3 Breaks FF2 Record > SNES is the Ultimate System > > > > SEGA Genesis > > Ogre Battle is sold out <--- > Sonic The Hedgehog an instant success > Joe Montanna Talking Football is amazing > > > > I'm using the Cooktop development environment. Its a freeware, and not supported anymore, but still works nicely. Processor Version: XSLT Processor VersionVendor: TransformiixVendor > > version="1.0" > > > > Under the first <item> element, two <category> elements are present. My present stylesheet ignores the second category, <category>SEGA</category>. Since 'Ogre Battle is sold out' also falls under 'SEGA' , it should also be posted under 'SEGA Genesis' > > in the output. > > > > I have reviewed possible solutions, but I have not figured it out. Any help is greatly appreciated. Thx :) -- Regards, Mukul Gandhi
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Grouping Problem - XML Repeat, Brent Solly | Thread | [xsl] Grouping Problem - XML Repeat, Brent Solly |
[xsl] Grouping Problem - XML Repeat, Brent Solly | Date | [xsl] Accessing every second node, Carlos German Ruiz I |
Month |