Reviewed by Hyatt.
authorap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Nov 2006 05:33:18 +0000 (05:33 +0000)
committerap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Nov 2006 05:33:18 +0000 (05:33 +0000)
        http://bugs.webkit.org/show_bug.cgi?id=11694
        XSLT output method does not default to HTML when the target document is HTML

        Test: fast/xsl/default-html.html

        * xml/XSLTProcessor.cpp:
        (WebCore::XSLTProcessor::transformToString): Make mimeType an input/output parameter,
        serving as a hint when the stylesheet doesn't specify the output method.
        (WebCore::XSLTProcessor::transformToFragment): Set mimeType to text/html if the target
        document is HTML.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@17902 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/xsl/default-html-expected.txt [new file with mode: 0644]
LayoutTests/fast/xsl/default-html.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/xml/XSLTProcessor.cpp

index 60d9b53a7d64e836ed95a97293cb19eff212f339..7006730a50067e46cf52a9c0c03b5bcce926c038 100644 (file)
@@ -1,3 +1,13 @@
+2006-11-27  Alexey Proskuryakov  <ap@webkit.org>
+
+        Reviewed by Hyatt.
+
+        Test for http://bugs.webkit.org/show_bug.cgi?id=11694
+        XSLT output method does not default to HTML when the target document is HTML
+
+        * fast/xsl/default-html-expected.txt: Added.
+        * fast/xsl/default-html.html: Added.
+
 2006-11-27  Kevin McCullough  <KMcCullough@apple.com>
 
         Reviewed by Adam.
diff --git a/LayoutTests/fast/xsl/default-html-expected.txt b/LayoutTests/fast/xsl/default-html-expected.txt
new file mode 100644 (file)
index 0000000..94a7eec
--- /dev/null
@@ -0,0 +1,7 @@
+Test for bug 11694: XSLT output method does not default to HTML when the target document is HTML.
+
+Should be green: result.
+Should be black: result.
+SUCCESS
+
+
diff --git a/LayoutTests/fast/xsl/default-html.html b/LayoutTests/fast/xsl/default-html.html
new file mode 100644 (file)
index 0000000..d3ff3b3
--- /dev/null
@@ -0,0 +1,48 @@
+<html>
+<body>
+<p>Test for <a href="http://bugs.webkit.org/show_bug.cgi?id=11694">bug 11694</a>:
+XSLT output method does not default to HTML when the target document is HTML.</p>
+<div id="result">Should be green: </div>
+<div id="result2">Should be black: </div>
+
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+var xsl = (new DOMParser()).parseFromString('<?xml version="1.0" encoding="ISO-8859-1"?>'+
+'<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">'+
+'<xsl:template match="doc">'+
+'<span style="color:green">result.</span>'+
+'</xsl:template>'+
+'</xsl:stylesheet>', 'application/xml');
+
+var xsl2 = (new DOMParser()).parseFromString('<?xml version="1.0" encoding="ISO-8859-1"?>'+
+'<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">'+
+'<xsl:output method="xml"/>'+
+'<xsl:template match="doc">'+
+'<span style="color:green">result.</span>'+
+'</xsl:template>'+
+'</xsl:stylesheet>', 'application/xml');
+
+var xml = (new DOMParser()).parseFromString('<?xml version="1.0" encoding="ISO-8859-1"?>'+
+'<doc/>', 'application/xml');
+
+var processor = new XSLTProcessor();
+processor.importStylesheet(xsl);
+var result = processor.transformToFragment(xml, document);
+
+document.getElementById("result").appendChild(result);
+
+// The HTML default shouldn't override an explicitly specified method.
+var processor = new XSLTProcessor();
+processor.importStylesheet(xsl2);
+result2 = processor.transformToFragment(xml, document);
+
+document.getElementById("result2").appendChild(result2);
+
+if (document.getElementById("result").childNodes[1].style.color == "green" && 
+      !document.getElementById("result2").childNodes[1].style)
+    document.write("<p>SUCCESS</p>");
+</script>
+</body>
+</html>
index 348bc94d5927129326aac5106d34d0b5beaed4f1..186b55f156252967629d18460c1d2b8b3087d97a 100644 (file)
@@ -1,3 +1,18 @@
+2006-11-27  Alexey Proskuryakov  <ap@webkit.org>
+
+        Reviewed by Hyatt.
+
+        http://bugs.webkit.org/show_bug.cgi?id=11694
+        XSLT output method does not default to HTML when the target document is HTML
+
+        Test: fast/xsl/default-html.html
+
+        * xml/XSLTProcessor.cpp:
+        (WebCore::XSLTProcessor::transformToString): Make mimeType an input/output parameter, 
+        serving as a hint when the stylesheet doesn't specify the output method.
+        (WebCore::XSLTProcessor::transformToFragment): Set mimeType to text/html if the target
+        document is HTML.
+
 2006-11-27  Oliver Hunt  <oliver@apple.com>
 
         Reviewed by Adam.
index ff184cb066d85aab1d9820b723050f23cd08b40a..fa6126f6c86b4c9696e451773569be87c901d1cf 100644 (file)
@@ -309,6 +309,10 @@ bool XSLTProcessor::transformToString(Node *sourceNode, DeprecatedString &mimeTy
     }
     cachedStylesheet->clearDocuments();
     
+    xmlChar* origMethod = sheet->method;
+    if (!origMethod && mimeType == "text/html")
+        sheet->method = (xmlChar*)"html";
+
     bool success = false;
     bool shouldFreeSourceDoc = false;
     if (xmlDocPtr sourceDoc = xmlDocPtrFromNode(sourceNode, shouldFreeSourceDoc)) {
@@ -340,6 +344,7 @@ bool XSLTProcessor::transformToString(Node *sourceNode, DeprecatedString &mimeTy
         xmlFreeDoc(resultDoc);
     }
     
+    sheet->method = origMethod;
     setXSLTLoadCallBack(0, 0, 0);
     xsltFreeStylesheet(sheet);
 
@@ -356,11 +361,16 @@ RefPtr<Document> XSLTProcessor::transformToDocument(Node *sourceNode)
     return createDocumentFromSource(resultString, resultEncoding, resultMIMEType, sourceNode);
 }
 
-RefPtr<DocumentFragment> XSLTProcessor::transformToFragment(Node *sourceNode, Document *outputDoc)
+RefPtr<DocumentFragment> XSLTProcessor::transformToFragment(Node* sourceNode, Document* outputDoc)
 {
     DeprecatedString resultMIMEType;
     DeprecatedString resultString;
     DeprecatedString resultEncoding;
+
+    // If the output document is HTML, default to HTML method.
+    if (outputDoc->isHTMLDocument())
+        resultMIMEType = "text/html";
+    
     if (!transformToString(sourceNode, resultMIMEType, resultString, resultEncoding))
         return 0;
     return createFragmentFromSource(resultString, resultMIMEType, sourceNode, outputDoc);