-
Bug
-
Resolution: Fixed
-
P3
-
5.0
-
b90
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.5.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
The default xsl transformer factory in java 1.5 (com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl) incorrect handles a null from an extension function. Instead of outputting nothing, it outputs the string value of the current node of the source document. Xalan (org.apache.xalan.processor.TransformerFactoryImpl) does handle this correctly. See code below.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the test.Test class included.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Both transformer factories should produce the same output
ACTUAL -
The XSLTC transformer factory fails to output what it should
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
/*
* Created on Nov 19, 2004
*
*/
package test;
import java.io.InputStream;
import java.io.StringBufferInputStream;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
/**
* @author bkrug
*
*/
public class Test {
private static final String xslText =
"<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" " +
"xmlns:system=\"xalan://test.Test\" version=\"1.0\">" +
"<xsl:template match=\"/\">" +
"<xsl:for-each select=\"symbols/*\">" +
"The following should be blank: '<xsl:value-of select=\"system:giveNull()\"/>'.\n" +
"</xsl:for-each>" +
"</xsl:template>" +
"</xsl:stylesheet>";
public static void main(String[] args) throws Throwable {
testNull("org.apache.xalan.processor.TransformerFactoryImpl");
testNull("com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
}
public static void testNull(String transformerFactoryClass) throws Throwable {
System.setProperty("javax.xml.transform.TransformerFactory", transformerFactoryClass);
String xml = "<symbols><letter>A</letter><letter>B</letter><number>1</number><number>2</number><letter>C</letter><letter>D</letter><number>3</number><letter>E</letter></symbols>";
InputStream xsl = new StringBufferInputStream(xslText);
TransformerFactory tf = TransformerFactory.newInstance();
System.out.println("*** Running a test using TransformerFactory " + tf.getClass().getName());
Transformer t = tf.newTransformer(new StreamSource(xsl));
t.transform(new StreamSource(new StringBufferInputStream(xml)), new StreamResult(System.out));
System.out.println();
System.out.println("*** Done running this test");
System.out.println();
}
public static Object giveNull() {
return null;
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use a different xsl transformer factory
###@###.### 2005-06-03 22:33:55 GMT
java version "1.5.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
The default xsl transformer factory in java 1.5 (com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl) incorrect handles a null from an extension function. Instead of outputting nothing, it outputs the string value of the current node of the source document. Xalan (org.apache.xalan.processor.TransformerFactoryImpl) does handle this correctly. See code below.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the test.Test class included.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Both transformer factories should produce the same output
ACTUAL -
The XSLTC transformer factory fails to output what it should
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
/*
* Created on Nov 19, 2004
*
*/
package test;
import java.io.InputStream;
import java.io.StringBufferInputStream;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
/**
* @author bkrug
*
*/
public class Test {
private static final String xslText =
"<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" " +
"xmlns:system=\"xalan://test.Test\" version=\"1.0\">" +
"<xsl:template match=\"/\">" +
"<xsl:for-each select=\"symbols/*\">" +
"The following should be blank: '<xsl:value-of select=\"system:giveNull()\"/>'.\n" +
"</xsl:for-each>" +
"</xsl:template>" +
"</xsl:stylesheet>";
public static void main(String[] args) throws Throwable {
testNull("org.apache.xalan.processor.TransformerFactoryImpl");
testNull("com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
}
public static void testNull(String transformerFactoryClass) throws Throwable {
System.setProperty("javax.xml.transform.TransformerFactory", transformerFactoryClass);
String xml = "<symbols><letter>A</letter><letter>B</letter><number>1</number><number>2</number><letter>C</letter><letter>D</letter><number>3</number><letter>E</letter></symbols>";
InputStream xsl = new StringBufferInputStream(xslText);
TransformerFactory tf = TransformerFactory.newInstance();
System.out.println("*** Running a test using TransformerFactory " + tf.getClass().getName());
Transformer t = tf.newTransformer(new StreamSource(xsl));
t.transform(new StreamSource(new StringBufferInputStream(xml)), new StreamResult(System.out));
System.out.println();
System.out.println("*** Done running this test");
System.out.println();
}
public static Object giveNull() {
return null;
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use a different xsl transformer factory
###@###.### 2005-06-03 22:33:55 GMT