Jump to content

Getting HTML back, instead of XHTML


MrAdam
 Share

Recommended Posts

Hey up again,Quite comfortable with XSLT now, but have a puzzling problem. In my <xsl:output ... /> tag, I'm specifying the 'doctype-public' and 'doctype-system' attributes as the correct values for XHTML Strict 1.0:

	<xsl:output		method="html"		version="1.0"		encoding="UTF-8"		indent="yes"		doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"		doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" />

However when I view the source code of the web page, the mark-up is HTML with an XHTML DOCTYPE? Also nothing is indented, like I'd expect to see with indent="yes"?Any help or advise would be greatly appreciated!Thanks

Link to comment
Share on other sites

Well if you use an XSLT 1.0 processor then specifying 'method="html"' together with an XHTML doctype does not make sense in my view as XSLT 1.0 predates XHTML 1.0 and thus has no method specifically geared towards XHTML.Event with an XSLT 2.0 processor your combination does not make sense as "html" output method is for HTML 4 with XSLT 2.0 while "XHTML 1.0" to be served as text/html is to be output with output method "xhtml".Finally if you simply want XHTML to be served as XML or XHTML (i.e. text/xml or application/xml or application/xhtml+xml) that browsers like Firefox or Opera or IE 9 parse as XML you should use output method "xml" with the XHTML doctype. Note however that IE 6, 7, and 8 don't know how to parse and render XHTML as XML so on the web for all kind of browser users if you use XSLT 1.0 you should better consider HTML 4 with output method "html".As for indentation, which XSLT processor do you use, how do you look at the transformation result?

Link to comment
Share on other sites

Sorted, cheers. I switched it to "xml" and omitted the opening XML tag. I just have one more question though...I have some XHTML like:

<h3><span>#1</span> Product Title</h3>

Where "1" and "Product Title" are replaced by the XML value. That's all fine, but when it's processed the space between the closing span tag and the start of the title text is stripped out. So the result looks like:

#1Product Title
I came across the "xml:space" attribute:
<h3 xml:space="preserve">

This works works visually, but oddly it's still shown within the source afterwards..?Thanks for all your help.

Link to comment
Share on other sites

There are some XML parsers respectively XSLT processors (notable MSXML and Altova) that strip white space text nodes but in your case the white space is part of a text node with other contents so I am not sure why any parser or processor would strip it.You would need to provide more details as to which parser and processor you use if you want us to reproduce and understand the problem first to then help fix or avoid it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...