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
+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.
--- /dev/null
+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
+
+
--- /dev/null
+<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>
+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.
}
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)) {
xmlFreeDoc(resultDoc);
}
+ sheet->method = origMethod;
setXSLTLoadCallBack(0, 0, 0);
xsltFreeStylesheet(sheet);
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);