WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
10419
XSLTProcessor transformToFragment fails because of an XML declaration
https://bugs.webkit.org/show_bug.cgi?id=10419
Summary
XSLTProcessor transformToFragment fails because of an XML declaration
j_mckitrick
Reported
2006-08-15 09:53:00 PDT
Here is an example of applying an XSLT stylesheet 'x' to source xml node 'x': var t = new XSLTProcessor(); t.importStylesheet(x); var f = t.transformToFragment(s, document); d.innerHTML = ""; d.appendChild(f); In every case I have tried, the variable 'f' is NULL. A fragment is never returned.
Attachments
test case
(3.05 KB, application/zip)
2006-08-16 02:50 PDT
,
Alexey Proskuryakov
no flags
Details
inhibit XML declarations
(39.87 KB, patch)
2006-08-21 11:50 PDT
,
Alexey Proskuryakov
eric
: review+
Details
Formatted Diff
Diff
View All
Add attachment
proposed patch, testcase, etc.
Alexey Proskuryakov
Comment 1
2006-08-15 10:51:33 PDT
We've got a bunch of working examples in layout tests (e.g. fast/xsl/xslt-processer.html). Please provide a test case that illustrates the problem you are seeing.
j_mckitrick
Comment 2
2006-08-15 14:57:15 PDT
---------- file: xslt-frag.xml ---------- <?xml version="1.0" encoding="UTF-8"?> <report-types> <report-type>Report 1</report-type> <report-type>Report 2</report-type> <report-type>Report 2</report-type> </report-types> ---------- file: xslt-frag.xsl ---------- <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="
http://www.w3.org/1999/XSL/Transform
" version="1.0"> <xsl:template match="/report-types"> <table> <tr> <th>Options</th> </tr> <tr> <xsl:for-each select="report-type"> <td><xsl:value-of select="."/></td> </xsl:for-each> </tr> </table> </xsl:template> </xsl:stylesheet> ---------- test case ---------- // JCM var xml3 = getXMLDocument("xslt-frag.xml"); addXMLResult("xml source node", xml3); var xsl3 = getXMLDocument("xslt-frag.xsl"); addXMLResult("xsl transform node", xsl3); var p = new XSLTProcessor; p.importStylesheet(xsl3); var ownerDocument = document.implementation.createDocument("", "test", null); var f = p.transformToFragment(xml3, ownerDocument); alert(serializer.serializeToString(f)); //addResultExpectValueWhenSerialized("transformed fragment is table", f, serializer.serializeToString); // JCM
Alexey Proskuryakov
Comment 3
2006-08-16 02:50:22 PDT
Created
attachment 10049
[details]
test case
Alexey Proskuryakov
Comment 4
2006-08-16 02:59:34 PDT
Apparently, createFragmentFromSource() chokes on the XML declaration in a string produced by transformToString(), and rightfully so. To work around this problem while we are fixing it, you can inhibit XML declaration printout: <xsl:output method="xml" omit-xml-declaration="yes"/> Of course, this is not an issue with HTML fragments.
j_mckitrick
Comment 5
2006-08-16 09:31:38 PDT
(In reply to
comment #4
)
> Apparently, createFragmentFromSource() chokes on the XML declaration in a > string produced by transformToString(), and rightfully so. > > To work around this problem while we are fixing it, you can inhibit XML > declaration printout: > > <xsl:output method="xml" omit-xml-declaration="yes"/> > > Of course, this is not an issue with HTML fragments. >
Excellent! It works just fine for now. Even though you will fix the bug, perhaps the output declaration would be a good idea anyway for documentation purposes. I also changed the method to html and found that fixed a couple of other issues. So maybe that's the best way to deal with it?
Alexey Proskuryakov
Comment 6
2006-08-21 11:29:05 PDT
(In reply to
comment #5
)
> I also changed the method to html and found that fixed a couple of other > issues. So maybe that's the best way to deal with it?
I think this depends on the kind of your target document (whether it's HTML or XHTML).
Alexey Proskuryakov
Comment 7
2006-08-21 11:50:40 PDT
Created
attachment 10147
[details]
inhibit XML declarations Inhibit XML declaration printout in XSLTProcessor::transformToString(). Unless I'm missing something, this shouldn't affect anything but line numbers in error messages, which would decrease by one.
Eric Seidel (no email)
Comment 8
2006-08-21 16:11:16 PDT
Comment on
attachment 10147
[details]
inhibit XML declarations Looks good. r=me.
Alexey Proskuryakov
Comment 9
2006-08-21 21:25:25 PDT
Committed revision 15960.
j_mckitrick
Comment 10
2006-08-26 06:19:00 PDT
I'm having one last issue: If I want xml:output to be HTML, how do I include an encoding? I have no problem outputting XML as UTF-8, but how do I do the same with HTML?
Alexey Proskuryakov
Comment 11
2006-08-26 11:15:47 PDT
See <
http://www.sagehill.net/docbookxsl/OutputEncoding.html
> (found with Google).
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug