xsl-list
[Top] [All Lists]

Re: [xsl] How to convert a recursive function to a loop, using XSLT2.0?

2019-05-10 11:30:17
David Carlisle wrote:

I don't think you'd fill the stack if you wrote
the function such that the sequence of strings
was built up in an additional argument to the
function so that your xsl:choose just consisted
of a single recursive call in the iteration case,
and returning the full sequence, not nothing,
in the end case.

I gave that approach a try. See below. Unfortunately, it generates the same 
"Too many nested function calls" error. Did I implement your suggestion 
correctly?  /Roger

<xsl:function name="f:make-string-table-entries" as="element(String)*">
    <xsl:param name="total-size" as="xs:integer" />
    <xsl:param name="current-position" as="xs:integer" />
    <xsl:param name="sourceSeq" as="element(Byte)*" />
    
    <xsl:sequence select="f:make-string-table-entries-aux($total-size, 
xs:integer(0), $current-position, $sourceSeq, ())" />
    
</xsl:function>

<xsl:function name="f:make-string-table-entries-aux" as="element(String)*">
    <xsl:param name="total-size" as="xs:integer" />
    <xsl:param name="current-size" as="xs:integer" />
    <xsl:param name="current-position" as="xs:integer" />
    <xsl:param name="sourceSeq" as="element(Byte)*" />
    <xsl:param name="results" as="element(String)*" />
    
    <xsl:choose>
        <xsl:when test="$current-size ge $total-size">
            <xsl:sequence select="$results" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:variable name="string" 
select="f:make-element-from-null-terminated-string('String', $current-position, 
$sourceSeq)" as="element(String)"/>
            <xsl:variable name="length" select="string-length($string/text()) + 
1"/>  <!-- add 1 for the null terminator -->
            <xsl:sequence select="f:make-string-table-entries-aux($total-size, 
                xs:integer($current-size+$length), 
                xs:integer($current-position+$length), 
                $sourceSeq,
                ($results, $string))" />
        </xsl:otherwise>
    </xsl:choose>
    
</xsl:function>
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>
  • Re: [xsl] How to convert a recursive function to a loop, using XSLT2.0?, Costello, Roger L. costello(_at_)mitre(_dot_)org <=