[xslt] Tail-call optimization for call-template possible?



Hi!

I’m using XSL-T for the parsing escaped HTML inside XML.  Yes,
terrible, I know, but it’s the best I can do.

Anyway, I’m currently running out of stack space when trying to parse
longer strings and was wondering if anyone had actually considered
“tail-call optimizing” call-template to avoid running out of stack.
How much work would it be?

On my Cygwin installation the following script works, but changing the
test to 5175 causes a silent exit.

<?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" encoding="utf-8"/>

  <xsl:template match="/" name="rec">
    <xsl:param name="count" select="0"/>

    <xsl:choose>
      <xsl:when test="$count = 5174">
        <xsl:value-of select="$count"/>
      </xsl:when>

      <xsl:otherwise>
        <xsl:call-template name="rec">
          <xsl:with-param name="count" select="$count + 1"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>

(This is with --maxdepth 10000.)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]