Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 2nd, 2008, 12:00 PM
Registered User
 
Join Date: Apr 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default recursive function problem

Hello,

I'm having trouble understanding why the following recursive function is generating an error:

Code:
  <xsl:template name="removeEndingChars">
    <xsl:param name="currStr" select="tst"/>
    <xsl:variable name="strLen" select="string-length($currStr)"/>
    <xsl:comment>Keep stripping end character until we reach a space, then display it</xsl:comment>

    <xsl:if test="substring($currStr, $strLen - 1, $strLen) = ' '">
      <xsl:value-of select="normalize-space($currStr)"/>...
    </xsl:if>

    <xsl:if test="substring($currStr, $strLen - 1, $strLen) != ' '">
      <xsl:variable name="splitStr" select="substring($currStr, 1, $strLen - 1)"/>
      <xsl:call-template name="removeEndingChars">
     <xsl:with-param name="currStr" select="$splitStr"/>
      </xsl:call-template>
    </xsl:if>

  </xsl:template>


The error is generated when I include the recursive call-template in the second if statement. Any help would be greatly appreciated.

 
Old April 2nd, 2008, 03:54 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Please tell us what the error is. The error message might be meaningless to you, but it's very likely to meaningful to someone more experienced, and it's the obvious starting place for investigating the problem.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 3rd, 2008, 03:11 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I suspect that the error is either a stack overflow or some kind of infinite recursion error.

Now you know this, and if you guess the reason for this is that the first <xsl:if> is always false, maybe you can try and figure out why that might be.

/- Sam Judson : Wrox Technical Editor -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in Recursive applying template ismomo XSLT 3 December 29th, 2007 11:35 PM
How to create a recursive function for combobox [email protected] PHP How-To 0 May 5th, 2007 04:04 AM
Problem in recursive call chennaiguy XSLT 3 March 22nd, 2007 11:18 AM
Recursive Function MargateFan XSLT 2 May 4th, 2006 02:52 AM
Help:Recursive Function - attributes into elements spencer.clark XSLT 1 June 10th, 2005 07:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.