Recursive call to function giving error in XSLT

xslt functions
xslt 3.0 functions
xslt transformation examples
xslt for each position() function
xslt validator
xslt get value-of element
xslt example
xml to xml transformation using xslt

I am writing a function to split string without breaking word. For that i have return function which is doing recursive call to itself. It's giving me below error

  1. When i am calling function with function prefix then getting error as "splitLine function under namespace http://whatever is not defined.".
  2. When i am calling function without function prefix then getting Parse error in the function.

When i Try to use

<xsl:value-of select="fn:splitLine($inString,$length - 1)"/>

in otherwise condition of function get function not defined error.

When i try to use without function prefix :

<xsl:value-of select="fn:splitLine($inString,$length - 1)"/>

I get parse error in Function.

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://whatever">
  <xsl:output omit-xml-declaration="no" /> 
  <xsl:output method="xml" /> 
<xsl:function name="fn:splitLine" as="xs:string">
        <xsl:param name="inString" as="xs:string"/>
        <xsl:param name="length" as="xs:numeric"/>
        <xsl:variable name="delimiters"> ,."!?()</xsl:variable>
        <xsl:choose>
            <xsl:when test="0.0 >= $length ">
                <xsl:value-of select="$inString"/>
            </xsl:when>
            <xsl:when test="$length >= string-length($inString)">
                <xsl:value-of select="$inString"/>
            </xsl:when>
            <xsl:when test="contains($delimiters,substring($inString,$length + 1,1))">
                <xsl:value-of select="substring($inString,1,$length)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="fn:splitLine($inString,$length - 1)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:function>
<xsl:template match="/">
<xsl:value-of select="fn:splitLine('3 ZHANLANGUAN RD XICHENG, , , BEIJING, , CN, ',35)"/>
  </xsl:template>
</xsl:stylesheet>

I am expecting output to be "3 ZHANLANGUAN RD XICHENG, , ," without breaking word.

This must be a quirk of your XSLT processor. I checked your XSLT-2.0 file with Saxon-HE 9.9.1.4J and it works as expected after adding the following namespace to the xsl:stylesheet element:

xmlns:xs="http://www.w3.org/2001/XMLSchema"

So, I guess, that your XSLT processor returned a different namespace as missing, because after adding the above one, all commands could be processed and the result is as expected.

Beginning XSLT 2.0: From Novice to Professional, This record of functions calling other functions is known as the stack. When you use recursive templates or functions, the stack can get very large; each time at that point the process stops altogether, and the stylesheet generates an error. see which one gives you the best performance with your data and your processor​. The Extensible Stylesheet Language Transformations (XSLT) processor returns the following error messages. The XSL processor stack has overflowed - probable cause is infinite template recursion. Keyword %1 may not be used here. The root of an XSL stylesheet must be an element. Keyword %1 may not follow %2. %1 is not a scripting language.

Below is the result for the processor and Version : Processor : Oracle Corporation. : Version :2 –

Right. Oracle (before they acquired Sun) were well down the path to developing an XSLT 2.0 processor as part of the Oracle XDK (XML development kit). But they never really finished it, and it never achieved a high level of conformance with the spec.

It looks to me as if you have encountered a restriction in that processor - and I'm sure there are many others. I don't think many people are using the Oracle XDK these days, and I think it has had very little development since Oracle acquired Sun (and hence Java).

XSLT Recursion | Blog, Provides an example of XSLT Recursion and its use in real-world scenarios. as it gives your code a certain level of elegance and simplicity. Recursion or in this case XSLT Recursion, is a particular type of function that calls itself as Business Proposals Efficiently · Custom Symphony CMS Error Pages  [RESOLVED] Recursive function in XSLT eeb3 I am trying to make a recursive function in XSLT, since it is the only way I seem to be able to do this in the V1.0 form, (and that the XSLT V2.0 isn't supported by IE7 and FF3 as of this point)

@Tim Thanks for the suggestion. Instead of using function , i Used named template and it worked perfectly fine :

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://whatever">
  <xsl:output omit-xml-declaration="no" /> 
  <xsl:output method="xml" />
  <xsl:template name="splitLine">
    <xsl:param name="inString"/>
    <xsl:param name="length"/>
    <xsl:variable name="delimiters"> ,."!?()</xsl:variable>
    <xsl:choose>
        <xsl:when test="0.0 >= $length ">
            <xsl:value-of select="$inString"/>
        </xsl:when>
        <xsl:when test="$length >= string-length($inString)">
            <xsl:value-of select="$inString"/>
        </xsl:when>
        <xsl:when test="contains($delimiters,substring($inString,$length + 1,1))">
            <xsl:value-of select="substring($inString,1,$length)"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:call-template name="splitLine">
                <xsl:with-param name="inString" select="$inString" />
                <xsl:with-param name="length" select="$length - 1" />
            </xsl:call-template>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template match="/">
    <xsl:call-template name="splitLine">
        <xsl:with-param name="inString" select="'fullnameofsample supplier in the block" />
        <xsl:with-param name="length" select="35" />
    </xsl:call-template>
</xsl:template>
</xsl:stylesheet>

XSL Transformations (XSLT) Version 3.0, When the value is set to true, the semantics of function calls and an API should be capable of returning any XDM value without error, and that there of the transformation is then the tree produced by this recursive process. Recursion or in this case XSLT Recursion, is a particular type of function that calls itself as many times as required to find the final solution. The most basic use-case is calculating the value of factorial numbers. Where a function calls itself to multiply the current number to the result of the same function -1.

limitation of the number of recursion - Saxon, Query processing failed: Run-time errors were reported" I know I have used many The best bet is to try and write your function to be tail-recursive (so that calling the recursive call reuse the stackframe of the caller, which in effect gives you highest-level language available (which in this case means XSLT or XQuery). XSLT is a functional programming language like Haskell or Scheme, and unlike C or Fortran. Thus it has no loops and no mutable variables. Instead, you must replace these constructs with recursion and parameters. This tip demonstrates how to provide this functionality using named templates and the xsl:call-template, xsl:with-param, and xsl:param elements.

XSLT Recursion Overview - TechLibrary, Series,QFX Series. XSLT depends on recursion as a looping mechanism. Recursion occurs when a section of code calls itself, either directly or indirectly. While XSLT does not define while and for loops, their behavior can be simulated. 5.67.9. A template can match from a selection of location paths, individual paths being separated with "|".

a Zen garden of XSLT and other tools, with (recursive) function calls in XSLT 2.0 and 3.0 and with named templates in Silent error means that the method produces well formed XML output that is showing us not only places where paragraph breaks occur in one witness to the  Re: error: recursive function call 2014/07/11 08:47:59 +2 (2) XC8 now supports recursive function calls if you change the compiler configuration to use a software stack.

Comments
  • Are you sure your processor supports XSLT 2.0?
  • What XSLT processor are you using? Your code works as expected under Saxon after adding a declaration for the "xs" (XML Schema) namespace.
  • Note also that the type xs:numeric is defined in XSLT 3.0 but not in XSLT 2.0.
  • Try adding <xsl:value-of select="system-property('xsl:vendor')"/> - <xsl:value-of select="system-property('xsl:version')"/> to your XSLT to find out exactly what processor/version you are using.
  • Below is the result for the processor and Version : Processor : Oracle Corporation. : Version :2
  • I updated my template and re-tried, but i am getting same error "org.xml.sax.SAXException: splitLine function under namespace whatever is not defined."
  • I cannot reproduce your error. So, unfortunately, I am unable to help you any further.