Description of problem: When processing a document where the DTD declaration is followed by a comment with a stylesheet that reproduces comments as-is, the new dtd is inserted after the comment : <?xml version="1.0"?> <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <!-- /etc/fonts.conf file to configure system font access --> Produces: <?xml version="1.0" encoding="UTF-8"?> <!-- /etc/fonts.conf file to configure system font access --><!DOCTYPE fontconfig SYSTEM "fonts.dtd"> which might be right but is certainly weird and not intended. Version-Release number of selected component (if applicable): libxslt-1.0.30-2 How reproducible: Always Steps to Reproduce: Use the attached test stylesheet on /etc/fonts/fonts.conf : xsltproc -path /etc/fonts register-vera.xsl /etc/fonts/fonts.conf | head -3 Actual results: <?xml version="1.0" encoding="UTF-8"?> <!-- /etc/fonts.conf file to configure system font access --><!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <fontconfig> Expected results: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <!-- /etc/fonts.conf file to configure system font access -->
Created attachment 92063 [details] Test stylesheet
The DOCTYPE does not come from the input document but from the doctype-system="fonts.dtd" instruction of the stylesheet xsl:output You cannot reasonably expect ordering to get respected there, the DOCTYPE information is not part of the XPath data model which is what the XSLt processor sees from the input XML documents. See http://www.w3.org/TR/xpath#data-model for the normative reference. There is no relationship between the input document DOCTYPE and the output document DOCTYPE. Daniel
Does this mean the doctype will be inserted at a random place in the document ? Surely not. The only xml docs I've seen where the doctype were not properly inserted at document startup were those generated by libxslt. I won't say it's invalid, just that it is plain weird. There is only a single doctype per document, is it so hard to put it at the top ? Even if doctypes might end up being phased out, I do expect them to stay with us for a few years at least.
Random, no. I think I will fix this. But I think you are wrong stating it "not properly inserted at document startup" I also suggest you read the XML spec http://www.w3.org/TR/REC-xml especially section 2.8: Prolog and Document Type Declaration "The document type declaration must appear before the first element in the document." and [22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)? Misc can generate a comment. Actually rereading the XSLt specification I really thing you are wrong: http://www.w3.org/TR/xslt#section-XML-Output-Method See section 16.1 XML Output Method "If the doctype-system attribute is specified, the xml output method should output a document type declaration immediately before the first element." "immediately before the first element" do imply after any comment or processing instruction generated before the first element, CQFD. To me it means "black on white" that libxslt behaviour is the Right Thing to do to comply to the XSLT-1.0 specification, and that your bug report is actually not a bug at all, but a wrong expectation pushed forward by someone who didn't care to read and understand the specs first. Am I wrong ? I am sorry if the XSLT spec is not specifying what you had in mind, but I will stick to the spec, unless there is an erratum on that point. If it means only document "were those generated by libxslt" are actually what an XSLT processor should output, well, I'm very sorry that other processors are not compliant, they are buggy, and you should ferocely report to them that their behaviour is not proper, as you tried with libxslt. Thanks in advance for getting the other implementations fixed for the sake of interoperability (or get the spec changed). Daniel
Really it does seem to me you are following the spec letter but not its spirit. I doubt whoever wrote this part intended stuff like comments to be shifted before the dtd, or its wording to be used as an excuse to do so. People certainly do not - all well-formed xml docs I know put the dtd before everything else and there are probably programs is the wild expecting it in this exact place. (Plus if you insist in putting the dtd after comments and misc stuff you should certainly at least respect the requested indenting and not start the dtd declaration in the middle of a line) I'm not asking you to do anything creative, just follow common usage that does matter at least as much as the actual spec (esp. wrt comments which are actually intended for humans not software) However I feel I will not convince you and since I'm not searching a fight here I'll let it rest now.
I follow the spec, and before getting on the spirit, did you read them ? The whoever in question is a W3C working group. I have been sitting on W3C Working Groups for the last 5 years, so thank you for your advice ! The XML Recommendation does specify what a well-formed XML instance is and it defines where the DOCTYPE can go. Libxslt generated instance is well-formed, I know what I'm saying thank you :-( (search for my name it is on that spec I'm part of the people maintaining it !) I don't care what other software do if they are broken, I really don't except I want them fixed, and you are right that suggesting that I make the code non-conformant is rightly something which is gonna annoy me to no end. And saying that common usage is more important than specs, I would then really suggest you don't try to speak with any authority in an XML topic, really, you would be roasted really really fast by the community ! Just try that on xml-dev if you want to get an idea ... Daniel