XSLTC tail recursion outputs backwards
--------------------------------------
Key: XALANJ-2003
URL: http://nagoya.apache.org/jira/browse/XALANJ-2003
Project: XalanJ2
Type: Bug
Components: XSLTC
Environment: J2SE 1.5. Also when using xsltc.jar from xalan-j_2_6_0
Reporter: Nick Sayer
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.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://nagoya.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]