need help to add a comment before <!DOCTYPE ... in xsl

J

jluo

Hi all,

Need some help here. I'm using these in a xsl:
~~~~~~~~~~~~~~~
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput method="html"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" indent="yes"/
<html>
<head>

After transform, the html output is:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
~~~~~~~~~
I will need to add a comment before the <!DOCTYPE ... and would like
the HTML output as:


<!-- something as a comment must be added here -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Can anyone please help? What can I do to create this comment? Can
this be done on the client side (xslt, scripting...) or should it be
done on the server side when Java code does the transform?

Any help is really appreciated!

Thanks in advance, Jane
 
M

Martin Honnen

jluo said:
I will need to add a comment before the <!DOCTYPE ... and would like
the HTML output as:


<!-- something as a comment must be added here -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Create a comment like this:

<xsl:template match="/">
<xsl:comment>a comment</xsl:comment>
<html xml:lang="en">
<head>
<title>a test</title>
</head>
<body>
<h1>Example</h1>
</body>
</html>
</xsl:template>

That way it will occur before the root element. Whether it will occur
before the DOCTYPE might be implementation dependent but a test here
with Saxon 6 puts the comment before the DOCTYPE.
 
J

jluo

Hi Martin,

Thanks for the help. It did work after I comment out the xsl:eek:utput.
It works great!

A good day,
Jane
 
G

Guest

That way it will occur before the root element. Whether it will occur
before the DOCTYPE might be implementation dependent

I believe it _is_ implementation dependent, at least in XSLT 1.0 where
the doctype is not an explicit part of the XPath 1.0 data model.
 
M

Martin Honnen

I believe it _is_ implementation dependent, at least in XSLT 1.0 where
the doctype is not an explicit part of the XPath 1.0 data model.

I don't think looking at the data model helps: we are talking about the
result of an XSLT 1.0 transformation where outputting a DOCTYPE
declaration is only possible as part of the serialization. For output
method="xml" the specification
<URL:http://www.w3.org/TR/xslt#section-XML-Output-Method> says:
"If the doctype-system attribute is specified, the xml output method
should output a document type declaration immediately before the first
element."
That could be read as a requirement to serialize a comment added with
xsl:comment outside of the root element before any DOCTYPE output by
<xsl:eek:utput doctype-system="..."/>.
 
G

Guest

"If the doctype-system attribute is specified, the xml output method
should output a document type declaration immediately before the first
element."
That could be read as a requirement to serialize a comment added with
xsl:comment outside of the root element before any DOCTYPE output by
<xsl:eek:utput doctype-system="..."/>.

I agree it could be read that way. I'm not sure this was the intent,
nor how many implementations actually exhibit that exact behavior...
I'd also note that in the spec there's an important distinction in
most W3C specs between SHOULD and MUST, and that the use of the former
would at most mean this is recommended-but-not-required behavior.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top