user811416
user811416

Reputation: 205

Setting doctype transitional for xhtml file fails

I'm trying to generate this line in a html file:

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

Since I generate the html file using an xsl file and an xml file, I think the code used to generate the line should be included in the xsl file.

I found this solution on Internet ----

<xsl:output method="html" doctype-system="http://www.w3.org/TR/html4/strict.dtd" doctype-public="-//W3C//DTD HTML 4.01//EN" indent="yes" />

but when I change strict to transitional, things go wrong.

Does anyone have a good solution?

Thank you in advance!

Upvotes: 0

Views: 1393

Answers (2)

therealmarv
therealmarv

Reputation: 3742

Your first and second line are not the same. Your desired output is XHTML but your found solution, the second line, describes HTML. Because you want XHTML (which is basically HTML with a XML Syntax) use this line like @empo (+1) already described:

<xsl:output method="xml" 
 doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" 
 doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" indent="yes"/>

Some XSLT processors also support xhtml as output method (like e.g. Saxon). But this is not a standard (in XSLT 1.0), use XML instead.

XML->XHTML conversion is no big difference compared to XML->XML.

Upvotes: 0

Emiliano Poggi
Emiliano Poggi

Reputation: 24826

This instruction is absolutely correct from the point of view of compilation:

<xsl:output 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"/>

It is not correct from the point of view of the doctype. Because you are going to generate a well-formed XML document based on a specific DTD you should better change your output method to xml:

<xsl:output method="xml" 
 doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" 
 doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" indent="yes"/>

However there is not reason why the first instruction above should not work. Maybe your XSLT processor takes care of the output method.

Upvotes: 1

Related Questions