Uploaded image for project: 'XalanJ2'
  1. XalanJ2
  2. XALANJ-2003

XSLTC tail recursion outputs backwards

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 2.7
    • XSLTC
    • Security Level: No security risk; visible to anyone (Ordinary problems in Xalan projects. Anybody can view the issue.)
    • None
    • J2SE 1.5. Also when using xsltc.jar from xalan-j_2_6_0

    Description

      Files:

      test-data.xml:

      <?xml version="1.0" encoding="utf-8"?>

      <rating>3</rating>

      test-temp.xml:

      <?xml version="1.0" encoding="utf-8"?>

      <rating>3</rating>
      %less test-temp.xml
      <?xml version="1.0" encoding="utf-8"?>
      <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="html"/>
      <xsl:template match="/">

      <html>
      <body>
      <xsl:call-template name="showRating">
      <xsl:with-param name="num" select="'1'"/>
      </xsl:call-template>
      </body>
      </html>
      </xsl:template>

      <!-- SHOW RATED STARS -->
      <xsl:template name="showRating">
      <xsl:param name="num"/>

      <xsl:if test="$num <= rating">
      <img border="0" src="yellow_star.gif" valign="absmiddle"/>
      </xsl:if>
      <xsl:if test="$num > rating">
      <img border="0" src="white_star.gif" valign="absmiddle"/>
      </xsl:if>

      <xsl:if test="$num <= '4'">

      <xsl:text>
      </xsl:text> <!-- CRLF -->

      <xsl:call-template name="showRating">
      <xsl:with-param name="num" select="$num + 1" />
      </xsl:call-template>

      </xsl:if>

      </xsl:template>
      </xsl:stylesheet>

      testxslt.java:

      import java.io.*;
      import javax.xml.transform.*;
      import javax.xml.transform.stream.*;

      public class testxslt {
      public static void main(String[] args) {
      try

      { new testxslt(); }

      catch(Throwable t)

      { System.err.println(t + ": " + t.getMessage()); t.printStackTrace(); }

      }

      private testxslt() throws Exception

      { String stylesheet = readFile("test-temp.xml"); String data = readFile("test-data.xml"); String out = transform(stylesheet, data); System.out.println(out); }

      private String readFile(String filename) throws IOException

      { StringBuffer out = new StringBuffer(); Reader r = new FileReader(filename); int count; char buf[] = new char[1024]; while((count = r.read(buf)) > 0) out.append(buf, 0, count); r.close(); return out.toString(); }

      private String transform(String stylesheet, String data) throws Exception

      { ByteArrayOutputStream resultStream = new ByteArrayOutputStream(); StreamResult transStreamResult = new StreamResult(resultStream); Source xmlData = new StreamSource(new StringReader(data)); StreamSource styleSource = new StreamSource(new StringReader(stylesheet)); TransformerFactory tf = TransformerFactory.newInstance(); //tf.setAttribute("debug", Boolean.TRUE); Templates t = tf.newTemplates(styleSource); Transformer trans = t.newTransformer(); trans.transform(xmlData, transStreamResult); return resultStream.toString(); }

      }

      If I add xalan.jar to the classpath, or if I run with J2SE 1.4 and add nothing to the classpath, the yellow stars are (correctly) printed first.

      If I run j2se 1.5 with no classpath additions, or if I add xsltc.jar to the classpath, the white stars are printed first.

      Attachments

        Issue Links

          Activity

            People

              santiago.pericasgeertsen@sun.com Santiago Pericas-Geertsen
              nsayer Nick Sayer
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: