Issue Details (XML | Word | Printable)

Key: XALANJ-2276
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Brian Minchau
Reporter: Brian Minchau
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
XalanJ2

<!DOCTYPE html .. is output for html output, even when the first element is not "html"

Created: 08/Mar/06 08:16 AM   Updated: 12/Dec/07 03:35 AM
Return to search
Component/s: Serialization
Affects Version/s: 2.7
Fix Version/s: 2.7.1

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works mini-patch7.txt 2006-03-11 01:23 AM Brian Minchau 2 kB
Text File Licensed for inclusion in ASF works patch3.txt 2006-03-09 01:08 PM Brian Minchau 2 kB
Text File Licensed for inclusion in ASF works patch4.txt 2006-03-10 01:13 AM Brian Minchau 3 kB
Text File Licensed for inclusion in ASF works patch5.txt 2006-03-10 04:53 AM Brian Minchau 5 kB
Text File Licensed for inclusion in ASF works patch6.txt 2006-03-10 06:51 AM Brian Minchau 5 kB

Xalan info: PatchAvailable
Reviewer: Henry Zongaro
Resolution Date: 11/Mar/06 02:41 AM


 Description  « Hide
Probably a minor bug, but the code in ToHTMLStream.java has this line:
  writer.write("<!DOCTYPE html");
in the method startDocumentInternal.

This method can be triggered by the fact that we got a startElement() call.
The DOCTYPE should apply to the first element, which is usually "html", but
could be "HTML" "HtMl" "spider" "fly" ... or whatever.

The code should be made a little more robust to get the name of the first element
and the name in the DOCTYPE to be the same.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Brian Minchau added a comment - 08/Mar/06 11:05 AM
Here is a sample XSL testcase that displays the problem:
<?xml version="1.0"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
<xsl:output method="html" doctype-system="html.dtd"/>
<xsl:template match="/">
  <Spider>Fly</Spider>
</xsl:template>
</xsl:stylesheet>


The output produced is:
<!DOCTYPE html SYSTEM "html.dtd">
<Spider>Fly</Spider>


The output produced should be:
<!DOCTYPE Spider SYSTEM "html.dtd">
<Spider>Fly</Spider>


Brian Minchau added a comment - 08/Mar/06 12:15 PM
Attaching patch2.txt, a patch to ToHTMLStream.java

Brian Minchau added a comment - 09/Mar/06 12:22 PM
A testcase for this issue is output40.xsl in the conf/output bucket. I uses the doctype-public <xsl:output> attribute, and the document-element in the result tree is <root>, not <html>.

The gold file for this testcase is:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional">
<root>
<Out> this tests nothing </Out>
<Out> this tests something </Out>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<Body></Body>
</HEAD>
</root>

I'm pretty sure that the <!DOCTYPE....> should be:
<!DOCTYPE root PUBLIC "-//W3C//DTD HTML 4.0 Transitional">

Brian Minchau added a comment - 10/Mar/06 01:13 AM
Attaching patch4.txt with addresses Henry Z's review comments that the name after the DOCTYPE should be the QName not the local name.

Other minor changes since patch2 were to add comments to the "comment" and "processingInstruction" methods to make it clear that perhaps in the future these nodes can exist before the DOCTYPE is output. But for now the DOCTYPE will occur before any comments or PIs.

Brian Minchau added a comment - 10/Mar/06 04:53 AM
Attaching patch5.txt which is a slight rework of patch.txt. Henry Zongaro found a bug during the review and this patch has that fix.

Henry found that a stylesheet like this:
<xsl:output method="html" doctype-system='abc' />
<xsl:template match="/">
  <xsl:comment>abc</xsl:comment>
  <html/>
</xsl:template>

put out two DOCTYPE declarations due to a latent bug in the comment() method, which didn't do the usual cleanup of pending issues, such
as closing opening start element tags, or handling what to do if no startDocument() call was received (other methods have such code).


Brian Minchau added a comment - 10/Mar/06 06:51 AM
Attaching patch6.txt - a performance improvement over the previous patch.

Henry Zongaro added a comment - 10/Mar/06 11:46 AM
I have reviewed Brian's patch6.txt,[1] and I believe that it correctly resolves the problem. However, I notice that there is new code in the ToHTMLStream.characters method that appears to be redundant' it duplicates code that appears in the try-catch block immediately after the new code.

[1] http://issues.apache.org/jira/secure/attachment/12323997/patch6.txt

Brian Minchau added a comment - 11/Mar/06 01:23 AM
Attaching mini-patch7.txt which catches a minor redundancy problem in ToHTMLStream.characters() method.
A condition for detecting and closing an open starting tag (which would have been triggered by a previous startElement() call)
was tested twice.

Henry Z. caught this in his review .... thanks Henry.

Henry Zongaro added a comment - 11/Mar/06 01:57 AM
I have reviewed and approve Brian's mini-patch7.txt.[2]

[2] http://issues.apache.org/jira/secure/attachment/12324030/mini-patch7.txt

Brian Minchau added a comment - 11/Mar/06 02:41 AM
Patches patch6.txt and mini-patch7.txt were applied to the latest code.
The issue is fixed/resolved.

Brian Minchau added a comment - 11/Dec/07 03:16 PM
This issue is no longer relevant for 2.7.1, it is fixed in 2.7.1.
Changing the affected version to 2.7.

Brian Minchau added a comment - 11/Dec/07 04:57 PM
Would the originator of this issue please verify that this issue is fixed in the 2.7.1 release, by adding a comment to this issue, so that we can close this issue.

A lack of response by February 1, 2008 will be taken as consent that we can close this resolved issue.

Regards,
Brian Minchau

Brian Minchau added a comment - 12/Dec/07 03:35 AM
closing this issue.