-
Bug
-
Resolution: Not an Issue
-
P4
-
6u31
-
x86
-
windows_xp
FULL PRODUCT VERSION :
JDK 1.6.0_24
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP, Professional, version 2002. Service Pack 3
EXTRA RELEVANT SYSTEM CONFIGURATION :
Tested output on Firefox 10.0.3 and IE 7.0.5730.13CO
A DESCRIPTION OF THE PROBLEM :
The javax.xml.Transform class is producing poorly formed XML/HTML. Any tag whose body is empty space, or that has no internal content is affected. Standalone tags are transformed and exported without the forward slash "/" before the closing bracket ">". For example, if my xsl document has "<br/>", the transform class will only export "<br>". It also appears to add a "META" tag to my html head section even if the xsl already included it, hence making a redundant tag. I do not believe it should be adding tags to the output at all, perhaps the developer did not want that tag to be in the final document. The exported document displays in a browser but cannot be loaded using javascript in some browsers. My xsl includes javascript that loads html from another page which was also produced by the Transform class. When the javascript attempts to load in the poorly formed html it throws an exception: "mismatched tag. Expected </META>". So it is unable to load the html into my web page via javascript.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Write an xsl transformation file that includes html. Add a link tag to the head section. Add a meta tag to the head section. Add a <br/> tag to the body. Use the javax.xml.Transform class to output the html file. Verify that all tags are missing the ending slash, and the html/xml is poorly formed.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected the html/xml to be well formed, and no tags be added during the transformation.
ACTUAL -
All tags that had no inner content were exported in a poorly formed format. The trailing slash "/" was missing for all tags that had no inner content. For example, there was <META ... > instead of <META ... />.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Error messages only appear when you use javascript to load the html page into another web page. The Firefox web console displays the error message "mismatched tag. Expected </META>"
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
XSL:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css"/>
</head>
<body>
Some text <br/>
More text
</body>
</html>
</xsl:template>
</xsl:stylesheet>
java code:
TransformerFactory tf = TransformerFactory.newInstance();
// some function that loads the xsl to a string:
String xsl = loadXSL();
// some function that loads the xml to a string:
String xml = loadXML();
File file = new File("C:\temp\output.html");
Transform t = tf.newTransformer(xsl);
Source src = new StreamSource(new StringReader(xml));
Result res = new StreamResult(new FileWriter(file));
t.transform(src,res);
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
If I put content in the body of these tags, that helps. For example, instead of having "<link ... />" I need to have "<link ... >a</link>"
JDK 1.6.0_24
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP, Professional, version 2002. Service Pack 3
EXTRA RELEVANT SYSTEM CONFIGURATION :
Tested output on Firefox 10.0.3 and IE 7.0.5730.13CO
A DESCRIPTION OF THE PROBLEM :
The javax.xml.Transform class is producing poorly formed XML/HTML. Any tag whose body is empty space, or that has no internal content is affected. Standalone tags are transformed and exported without the forward slash "/" before the closing bracket ">". For example, if my xsl document has "<br/>", the transform class will only export "<br>". It also appears to add a "META" tag to my html head section even if the xsl already included it, hence making a redundant tag. I do not believe it should be adding tags to the output at all, perhaps the developer did not want that tag to be in the final document. The exported document displays in a browser but cannot be loaded using javascript in some browsers. My xsl includes javascript that loads html from another page which was also produced by the Transform class. When the javascript attempts to load in the poorly formed html it throws an exception: "mismatched tag. Expected </META>". So it is unable to load the html into my web page via javascript.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Write an xsl transformation file that includes html. Add a link tag to the head section. Add a meta tag to the head section. Add a <br/> tag to the body. Use the javax.xml.Transform class to output the html file. Verify that all tags are missing the ending slash, and the html/xml is poorly formed.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected the html/xml to be well formed, and no tags be added during the transformation.
ACTUAL -
All tags that had no inner content were exported in a poorly formed format. The trailing slash "/" was missing for all tags that had no inner content. For example, there was <META ... > instead of <META ... />.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Error messages only appear when you use javascript to load the html page into another web page. The Firefox web console displays the error message "mismatched tag. Expected </META>"
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
XSL:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css"/>
</head>
<body>
Some text <br/>
More text
</body>
</html>
</xsl:template>
</xsl:stylesheet>
java code:
TransformerFactory tf = TransformerFactory.newInstance();
// some function that loads the xsl to a string:
String xsl = loadXSL();
// some function that loads the xml to a string:
String xml = loadXML();
File file = new File("C:\temp\output.html");
Transform t = tf.newTransformer(xsl);
Source src = new StreamSource(new StringReader(xml));
Result res = new StreamResult(new FileWriter(file));
t.transform(src,res);
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
If I put content in the body of these tags, that helps. For example, instead of having "<link ... />" I need to have "<link ... >a</link>"