Bug 91990 - DTD declaration is not inserted at the right place by xsltproc
Summary: DTD declaration is not inserted at the right place by xsltproc
Alias: None
Product: Red Hat Raw Hide
Classification: Retired
Component: libxslt   
(Show other bugs)
Version: 1.0
Hardware: All Linux
Target Milestone: ---
Assignee: Daniel Veillard
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 2003-05-30 18:24 UTC by Nicolas Mailhot
Modified: 2007-04-18 16:54 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2003-07-14 19:41:17 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
Test stylesheet (1.84 KB, text/xml)
2003-05-30 18:27 UTC, Nicolas Mailhot
no flags Details

Description Nicolas Mailhot 2003-05-30 18:24:42 UTC
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 -->


<?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):


How reproducible:

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">

Expected results:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- /etc/fonts.conf file to configure system font access -->

Comment 1 Nicolas Mailhot 2003-05-30 18:27:32 UTC
Created attachment 92063 [details]
Test stylesheet

Comment 2 Daniel Veillard 2003-07-14 17:55:37 UTC
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
for the normative reference.
There is no relationship between the input document DOCTYPE and
the output document DOCTYPE.


Comment 3 Nicolas Mailhot 2003-07-14 18:42:27 UTC
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.

Comment 4 Daniel Veillard 2003-07-14 19:41:17 UTC
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
especially section 2.8: Prolog and Document Type Declaration

"The document type declaration must appear before the first element in the
[22]    prolog    ::=    XMLDecl? Misc* (doctypedecl Misc*)?

  Misc can generate a comment.

Actually rereading the XSLt specification I really thing you are wrong:

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).


Comment 5 Nicolas Mailhot 2003-07-14 21:23:12 UTC
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.

Comment 6 Daniel Veillard 2003-07-14 22:27:48 UTC
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 ...


Note You need to log in before you can comment on or make changes to this bug.