Re: [xsl] summing, ok

Subject: Re: [xsl] summing, ok
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Sun, 13 Feb 2005 01:41:24 -0800 (PST)
So you wish to count unique models.. This is a
grouping problem... (and Muenchian grouping technique
first comes to my mind)

Please try this XSL -

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  
<xsl:output method="text" />    
  
<xsl:key name="by-model" match="car" use="model" />
  
<xsl:template match="/cars">
  <xsl:variable name="modelcount">
    <xsl:for-each select="car[generate-id(.) =
generate-id(key('by-model',model)[1])]">  
      1      
    </xsl:for-each>    
  </xsl:variable>

  Total no of models - <xsl:value-of
select="string-length($modelcount) -
string-length(translate($modelcount,'1',''))" />

</xsl:template>  
 
</xsl:stylesheet>

Regards,
Mukul

--- Marcos Hercules dos Santos <mhercules@xxxxxxxxx>
wrote:

> Thanks Mukul Gandhi, 
>  the stage 1 from summing  used  by exemplification
> - cars. It's all ok, cool.
> thanks
> 
> Going on,  based in the same question,  how  must do
> I to proceed to
> group a tag and totalize itself.
> 
> Using the same example:
> 
> <cars> 
>    <car>
> 		<model>V667320</model>
> 		<name>Sportage</name>
>                 <categ>sport</categ>
> 
>    </car>
>    <car>
> 		<model>M382932</model>
> 		<name>Silverado</name>
>                <categ>pick-up</categ>
>  </car>
> 
> Imagine that the first element (model) be written
> five times, the
> second model two times, and other  any model  four
> times. Supposing
> that this could be a greatest structure with 25
> models and many
> occurences to it , how to do to generate the total
> number of models
> and not  occurences
> 
> The Total number  to display =  25 
> 
> if  consider the three , then  = 3   and  not   
> 5+2+4
> 
>  
> Marcos Hercules dos Santos


		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250

Current Thread