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] Recursively looping through a template only X number of times?
by Brian Martinez other posts by this author
Nov 28 2006 2:08PM messages near this date
RE: [xsl] Recursively looping through a template only X number of times? | RE: RE: [xsl] Recursively looping through a template only X number of times?
& XSLT >  The problem appears to be that xsl:with-param can not be a child of
>  xsl:template, so I can't call the template recursively while changing
>  the param value.

It's true that xsl:with-param cannot be a child of xsl:template, but
that's not the point: to use recursion you need to call the template
from within itself, using xsl:call-template.  Brief example:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0"> 
<xsl:output method="html"/> 

<xsl:template match="/"> 
  <xsl:call-template name="xyzTemp"> 
    <xsl:with-param name="counter" select="1"/> 
  </xsl:call-template> 
</xsl:template> 

<xsl:template name="xyzTemp"> 
  <xsl:param name="counter"/> 
  This is line <xsl:value-of select="$counter"/> .<xsl:value-of
select="'%
  <xsl:if test="$counter &lt; 10"> 
    <xsl:call-template name="xyzTemp"> 
      <xsl:with-param name="counter" select="$counter + 1"/> 
    </xsl:call-template> 
  </xsl:if> 
</xsl:template> 

</xsl:stylesheet> 

hth,
b.

>  -----Original Message-----
>  From: Austin, Darrel [mailto:Darrel.Austin@[...].us]
>  Sent: Tuesday, November 28, 2006 12:17 PM
>  To: xsl-list@[...].com
>  Subject: RE: [xsl] Recursively looping through a template only X
number of
>  times?
>  
>  > You want to use template parameters. Declare xsl:param inside
>  > the template, and use xsl:with-param to set a value on the call.
>  
>  The problem appears to be that xsl:with-param can not be a child of
>  xsl:template, so I can't call the template recursively while changing
>  the param value.
>  
>  > Just have
>  > <xsl:variable name="tocdepth" select="2"/>
>  > then wrap your code in
>  > <xsl:if test="count(ancestor::ruleItem)&lt;=$tocdepth">
>  > .. make a toc entry...
>  > </xsl:if>
>  
>  Of course! Makes perfect sense. That works nicely.
>  
>  That said, I'm still curious as to how (or if) one can create
recursive
>  logic that can 'count' the recursions via XSL.
>  
>  -Darrel
>  
>  --~------------------------------------------------------------------
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>  To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
>  or e-mail: <mailto:xsl-list-unsubscribe@[...].com>
>  --~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@[...].com> 
--~--
Thread:
Darrel Austin
Michael Kay
Brian Martinez
Darrel Austin
Darrel Austin

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