help counter recursive template

  • Thread starter Petterson Mikael
  • Start date
P

Petterson Mikael

Hi,

I call the sequenceNameString template with:

<xsl:when test="child::*[name() = 'sequence']">
<xsl:call-template name="sequenceNameString">
<xsl:with-param name="sequenceName" select="@name"/>
<xsl:with-param name="maxCount" select="sequence/maxLength"/>
<xsl:with-param name="value" select="0"/>
</xsl:call-template></xsl:when>

I can check that the parameter values are sent to the template.
However the incrementation of value does not happen.

I get the following only once( example):

eAgchCodes_name0

but want:

eAgchCodes_name0
eAgchCodes_name1
eAgchCodes_name2
.......

Any ideas why?

cheers,

//Mikael

!-- Template that create "<sequencename>_name0", "<sequencename>_name1"..-->
<xsl:template name="sequenceNameString">
<xsl:param name="sequenceName"/>
<xsl:param name="maxCount"/>
<xsl:param name="value"/>
<xsl:param name="arrayMax" select="$maxCount - 1"/>
<xsl:if test="$value &lt; $arrayMax">
<xsl:value-of
select="concat(concat($sequenceName,'_name'),$value)"/>
<xsl:call-template name="sequenceNameString">
<xsl:with-param name="value" select="$value + 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
 
J

Joe Kesselman

Haven't examined it in detail, but I note one glitch: You aren't passing
maxCount down through the recursive call.
 
J

Joe Kesselman

Yep, that was it. (You're also not outputting line breaks between the
generated names, but I'll leave that as an exercise for the student.)

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

<xsl:template match="/">
<xsl:call-template name="sequenceNameString">
<xsl:with-param name="sequenceName" select="'SN'"/>
<xsl:with-param name="maxCount" select="4"/>
<xsl:with-param name="value" select="0"/>
</xsl:call-template>
</xsl:template>

<xsl:template name="sequenceNameString">
<xsl:param name="sequenceName"/>
<xsl:param name="maxCount"/>
<xsl:param name="value"/>
<!-- You used xsl:param for arrayMax; should have been variable. -->
<xsl:variable name="arrayMax" select="$maxCount - 1"/>
<xsl:if test="$value &lt; $arrayMax">
<xsl:value-of
select="concat(concat($sequenceName,'_name'),$value)"/>
<xsl:call-template name="sequenceNameString">
<!-- The real bug was that you forgot to pass both
sequenceName and maxCount. -->
<xsl:with-param name="sequenceName" select="$sequenceName"/>
<xsl:with-param name="value" select="$value + 1"/>
<xsl:with-param name="maxCount" select="$maxCount"/>
</xsl:call-template>
</xsl:if>
</xsl:template>

</xsl:stylesheet>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top