ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> xsl-list
xsl-list
RE: [xsl] getting the counter for a for-each statement
by Jaime A Stuardo Bahamondes other posts by this author
Dec 11 2003 6:22PM messages near this date
Re: [xsl] Different templates for same set of nodes | Re: [xsl] getting the counter for a for-each statement
That doesn't work since the context node isn't the node for the for-each.

This is the complete for-each:

<xsl:for-each select="ROW[count(. | key('tipos', D)[1]) = 1]"> 
  a_valores[<xsl:value-of select="position()-1" /> ] = new Array(<xsl:value-of select="count(
. | key('tipos', A)[1])" /> );      
  a_valores[<xsl:value-of select="position()-1" /> ][<xsl:value-of select="count(. | key('tip
os', D))-1" /> ] = new Array(2);
  a_valores[<xsl:value-of select="position()-1" /> ][<xsl:value-of select="count(. | key('tip
os', D))-1" /> ][0] = <xsl:value-of select="D" />;
  a_valores[<xsl:value-of select="position()-1" /> ][<xsl:value-of select="count(. | key('tip
os', D))-1" /> ][1] = <xsl:value-of select="D" />;  
</xsl:for-each> 

This follows the muenchian grouping algorithm. In that case position() gets the parent of RO
W since the template is:
<xsl:template match="ficha_tecnica/ROWSET"> 

The way I have now is by using count(. | key('tipos', D)) and it works, but I think that if 
I have more data, that process will be inefficient since it has to count the actual nodes fo
r each iteration.

My for-each gets the following:

a_valores[0] = new Array(1);      
a_valores[0][0] = new Array(2);
a_valores[0][0][0] = .30726074;
a_valores[0][0][1] = .30726074;  
      
a_valores[1] = new Array(1);      
a_valores[1][0] = new Array(2);
a_valores[1][0][0] = .12244368;
a_valores[1][0][1] = .12244368;  
      
a_valores[2] = new Array(1);      
a_valores[2][0] = new Array(2);
a_valores[2][0][0] = .4071683;
a_valores[2][0][1] = .4071683;  


Jaime

>  -----Mensaje original-----
>  De: owner-xsl-list@[...].com
>  [mailto:owner-xsl-list@[...].com]En nombre de David
>  Carlisle
>  Enviado el: Jueves, 11 de Diciembre de 2003 12:32
>  Para: xsl-list@[...].com
>  Asunto: Re: [xsl] getting the counter for a for-each statement
>  
>  
>  
>  this has already been answered today in a differentthread.
>  <xsl:value-of select="position()"/>
>  
>  
>  
>  -- 
>  http://www.dcarlisle.demon.co.uk/matthew
>  
>  ______________________________________________________________
>  __________
>  This e-mail has been scanned for all viruses by Star Internet. The
>  service is powered by MessageLabs. For more information on a proactive
>  anti-virus service working around the clock, around the globe, visit:
>  http://www.star.net.uk
>  ______________________________________________________________
>  __________
>  
>   XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>  
>  
>  

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
Thread:
Jaime A Stuardo Bahamondes
David Carlisle

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved