[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Grouping elements

Subject: Re: Grouping elements
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Fri, 25 Mar 2005 09:51:39 -0800 (PST)
ranger name
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))
&gt; 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>&#xa;</xsl:text>
      occurence: <xsl:value-of
select="count(key('by-model',model))"
/><xsl:text>&#xa;</xsl:text>
      Total stock: <xsl:value-of
select="sum(key('by-model',model)/stock)"
/><xsl:text>&#xa;</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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.