Subject: Re: [xsl] Grouping elements From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx> Date: Fri, 25 Mar 2005 09:51:39 -0800 (PST) |
Following is a Muenchian grouping solution.. <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text" /> <xsl:key name="by-model" match="car" use="model" /> <xsl:template match="/cars"> <xsl:for-each select="car[generate-id() = generate-id(key('by-model',model)[1])][count(key('by-model',model)) > 1]"> <xsl:sort select="model" order="descending" /> Car: <xsl:value-of select="model" /><xsl:text> </xsl:text><xsl:value-of select="name" /><xsl:text> </xsl:text><xsl:value-of select="categ" /><xsl:text>
</xsl:text> occurence: <xsl:value-of select="count(key('by-model',model))" /><xsl:text>
</xsl:text> Total stock: <xsl:value-of select="sum(key('by-model',model)/stock)" /><xsl:text>
</xsl:text> </xsl:for-each> </xsl:template> </xsl:stylesheet> Regards, Mukul --- Marcos Hercules dos Santos <mhercules@xxxxxxxxx> wrote: > Hi people . I've been working with grouped elements > and I'm having > problems with a kind of operation. Well, I'm trying > to group just the > elements with more of one occurence, to the others > elements that > appears just one time, there's no need to display. > Until now I > ain't have any success, Is There anyone to help me ? > I simplify > it this way: If I ha > <cars> > <car> > <model>J980384</model> > <name>Ranger</name> > <categ>Pick-up</categ> > <color>blue</color> > <stock>6</stock> > </car> > <car> > <model>V667320</model> > <name>Sportage</name> > <categ>sport</categ> > <color>green</color> > <stock>8</stock> > > </car> > <car> > <model>M382932</model> > <name>Silverado</name> > <categ>pick-up</categ> > <color>blue</color> > <stock>3</stock> > </car> > <car> > <model>L930389</model> > <name>Jaguar</name> > <categ>Sport</categ> > <color>red</color> > <stock>2</stock> > </car> > <car> > <model>J980384</model> > <name>Ranger</name> > <categ>Pick-up</categ> > <color>grey</color> > <stock>3</stock> > </car> > <car> > <model>L930389</model> > <name>Jaguar</name> > <categ>Sport</categ> > <color>blue</color> > <stock>1</stock> > </car> > <car> > <model>J980384</model> > <name>Ranger</name> > <categ>Pick-up</categ> > <color>black</color> > <stock>5</stock> > </car> > </cars> > > I Think through this example you'll understand what > I want to do. > > My question: I have Two categories: Supposing that > my structure have > more than 100 models, I need to group only those > have more of one > representation. How I'm selecting by the model > number, in this example > I wish that the grouped elements appear this way > > > Car: L930389 Jaguar Sport > occurence : 2 > > Total stock: 3 > > > Car: L930384 Ranger Pick-up > occurence : 3 > > Total stock: 14 > > The elements with one occurence shouldn't be showed > > Thanks . > > > Marcos Hercules dos Santos > > __________________________________ Do you Yahoo!? Make Yahoo! your home page http://www.yahoo.com/r/hs
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Grouping elements, Marcos Hercules dos | Thread | Re: [xsl] Grouping elements, Marcos Hercules dos |
Re: [xsl] how red ampersand from th, Joe Fawcett | Date | Re: [xsl] how red ampersand from th, henry human |
Month |