title: Zero width space in XSL gives stackoverflow error
body: <p>I'm using FOP 1.1, i've a text which can contain upto 20,000 characters and since there was text which didn't contain any spaces in between have modified the xsl to use the zero width space. It works fine if the xml tag contains around 1500 characters, if it is more than that i'm getting stack overflow error. Heap Space in weblogic server is also 2 GB.
  Can anyone help on this with a possible workaround or if there is any flaws in the xsl.</p>
  
  <p>Below is the xsl code sample  - </p>
  
  <pre><code>    &lt;xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:fo="http://www.w3.org/1999/XSL/Format"
      xmlns:locale="xalan://java.util.Locale" 
      xmlns:arrayList="xalan://java.util.ArrayList" 
      xmlns:func="http://exslt.org/functions" extension-element-prefixes="func"
      version="1.0"&gt;
  
  ..................
  
  
  
  
       &lt;fo:block&gt;
          &lt;xsl:value-of select="func:callTemplate(summaryData)"/&gt;
          &lt;/fo:block&gt;
  
  ..................
      &lt;xsl:template name="zero_width_space_1"&gt;
              &lt;xsl:param name="data"/&gt;
              &lt;xsl:param name="counter" select="0"/&gt;
              &lt;xsl:choose&gt;
                  &lt;xsl:when test="$counter &amp;lt; (string-length($data))"&gt;
                      &lt;xsl:value-of select='concat(substring($data,$counter,1),"&amp;#8203;")'/&gt;
                      &lt;xsl:call-template name="zero_width_space_2"&gt;
                          &lt;xsl:with-param name="data" select="$data"/&gt;
                          &lt;xsl:with-param name="counter" select="$counter+1"/&gt;
                      &lt;/xsl:call-template&gt;
                  &lt;/xsl:when&gt;
                  &lt;xsl:otherwise&gt;
                  &lt;/xsl:otherwise&gt;
              &lt;/xsl:choose&gt;
          &lt;/xsl:template&gt;
  
          &lt;xsl:template name="zero_width_space_2"&gt;
              &lt;xsl:param name="data"/&gt;
              &lt;xsl:param name="counter"/&gt;
              &lt;xsl:value-of select='concat(substring($data,$counter,1),"&amp;#8203;")'/&gt;
              &lt;xsl:call-template name="zero_width_space_1"&gt;
                  &lt;xsl:with-param name="data" select="$data"/&gt;
                  &lt;xsl:with-param name="counter" select="$counter+1"/&gt;
              &lt;/xsl:call-template&gt;
      &lt;/xsl:template&gt;
  
  
          &lt;func:function name="func:callTemplate"&gt;
              &lt;xsl:param name="string1"/&gt;
              &lt;xsl:call-template name="zero_width_space_1"&gt;
                  &lt;xsl:with-param name="data" select="$string1"/&gt;
              &lt;/xsl:call-template&gt;
              &lt;func:result/&gt;
          &lt;/func:function&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Below is the error which i'm getting - </p>
  
  <blockquote>
    <p>Caused by: java.lang.StackOverflowError   at
    org.apache.xml.utils.FastStringBuffer.append(FastStringBuffer.java:499)
      at
    org.apache.xml.dtm.ref.dom2dtm.DOM2DTM.getNodeData(DOM2DTM.java:935)
      at
    org.apache.xml.dtm.ref.dom2dtm.DOM2DTM.getNodeData(DOM2DTM.java:928)
      at
    org.apache.xml.dtm.ref.dom2dtm.DOM2DTM.getStringValue(DOM2DTM.java:827)
      at
    org.apache.xpath.objects.XNodeSet.getStringFromNode(XNodeSet.java:217)
      at org.apache.xpath.objects.XNodeSet.xstr(XNodeSet.java:256)    at
    org.apache.xpath.functions.FunctionDef1Arg.getArg0AsString(FunctionDef1Arg.java:97)
      at
    org.apache.xpath.functions.FuncStringLength.execute(FuncStringLength.java:45)
      at org.apache.xpath.Expression.execute(Expression.java:155)     at
    org.apache.xpath.operations.Operation.execute(Operation.java:110)     at
    org.apache.xpath.Expression.bool(Expression.java:186)     at
    org.apache.xpath.XPath.bool(XPath.java:412)   at
    org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:126)    at
    org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
      at
    org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:394)
      at
    org.apache.xalan.templates.ElemCallTemplate.execute(ElemCallTemplate.java:248)</p>
  </blockquote>