Jump to content

XSL output


Guest FirefoxRocks

Recommended Posts

Guest FirefoxRocks

I have read this page: http://w3schools.com/xsl/el_output.asp and I want to know how do I use this element in my XSLT stylesheet.Like if I put this in, what will it do?

<xsl:output method="html" version="4.01" encoding="utf-8" standalone="no" indent="yes"media-type="text/html"/>

Link to comment
Share on other sites

The xsl:output element most often gives instructions to the XML serializer, i.e. how to output the XML document as text once the transformation is finished.Your sample will output an indented HTML document encoded as UTF-8 (the "standalone" and "version" attribute are ignored for the "html" method. They apply only in XML outputs).The media-type attribute suggests to a user agent what MIME type to use before parsing the output document. Unfortunatly, no user agent implements it (and as by the spec, they don't have to either).Note that Firefox doesn't serialize documents. That is why if you use an XHTML DTD and the "html" method in xsl:output, you'll get a true XHTML rendering in Firefox, and HTML in IE - Firefox never realizes this is an HTML document - it receives only the DOM tree, and the XHTML DTD is part of it. Thanks to that DTD, the tree is treated like true XHTML.

Link to comment
Share on other sites

  • 4 weeks later...
Guest FirefoxRocks

Ok, I'm confused. I don't notice any difference in IE or Firefox with or without that line.

Link to comment
Share on other sites

Ok, I'm confused. I don't notice any difference in IE or Firefox with or without that line.
Try it in PHP. You'll see the difference there.As I said, Firefox never performs serialization, which is the source of most XSLT related bugs in it. You can't notice this on every page though. You need a specific test case where the serialized ouput would be parsed differently than the DOM tree, and XML is made to allow very few such cases.And as for IE and Opera which do serialize their output, that output would still remain hidden for you, since when you click "View Source" you get the XML.When you do a transformation server side, the output is serialized and you get that parsed by the browser as usual.OK... maybe I really need to suply a sample that makes a difference. Here's the case where I found that out myself the hard way:
<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	<xsl:output method="html" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"/>	<xsl:template match="/">		<html xmlns="http://www.w3.org/1999/xhtml">			<head>				<title>TEST</title>				<style type="text/css">				html {background-color:red;}/* this background applies in both text/html and application/xhtml+xml */				body {background-color:blue;} /* this background applies only in text/html. If you use application/xhtml+xml (i.e. Firefox), you'll see a red background */				</style>			</head>			<body>			</body>		</html>	</xsl:template></xsl:stylesheet>

XHTML 1.1 is forced into application/xhtml+xml, so Firefox always makes an assumption for it. Other browsers serialize the output, and because the method is "html", they assume it's text/html. If you use "xml", Opera will render the page as XHTML too, while IE will show the resulting XML tree.Most of the other serialization option don't make any difference in the rendering you see in the browser, but they all make a difference in how the source code looks. Do the transformation server side, and you'll see.

Link to comment
Share on other sites

Guest FirefoxRocks

So what code do I type in for the transformation to be on the server (like what PHP functions, etc)?

Link to comment
Share on other sites

So what code do I type in for the transformation to be on the server (like what PHP functions, etc)?
We've had that conversation before in this topic.
Link to comment
Share on other sites

  • 2 months later...

What if I want to do the same, only instead of using the block of straight html in there, I just want a portion that is acquired from the xml file being transformed? I have tried the following:xsl code:

<xsl:output method="html" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"/><xsl:template match="/"/><xsl:value-of select="wcm:root/wcm:element[@name='MyHTMLBlock']/node()" /></xsl:template>

to transform this xml:

<wcm:element name="MyHTMLBlock"><p>Type Code 01 Description</p><p>Type Code 02 Description</p><ul><li>List Item One</li><li>List Item Two</li><li>List Item Three</li></ul><p>Type Code 02 Description</p></wcm:element>

the ideal result would be that it outputs the html stuff in there as html that works like html as opposed to printing out in plain text.

Try it in PHP. You'll see the difference there.As I said, Firefox never performs serialization, which is the source of most XSLT related bugs in it. You can't notice this on every page though. You need a specific test case where the serialized ouput would be parsed differently than the DOM tree, and XML is made to allow very few such cases.And as for IE and Opera which do serialize their output, that output would still remain hidden for you, since when you click "View Source" you get the XML.When you do a transformation server side, the output is serialized and you get that parsed by the browser as usual.OK... maybe I really need to suply a sample that makes a difference. Here's the case where I found that out myself the hard way:
<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	<xsl:output method="html" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"/>	<xsl:template match="/">		<html xmlns="http://www.w3.org/1999/xhtml">			<head>				<title>TEST</title>				<style type="text/css">				html {background-color:red;}/* this background applies in both text/html and application/xhtml+xml */				body {background-color:blue;} /* this background applies only in text/html. If you use application/xhtml+xml (i.e. Firefox), you'll see a red background */				</style>			</head>			<body>			</body>		</html>	</xsl:template></xsl:stylesheet>

XHTML 1.1 is forced into application/xhtml+xml, so Firefox always makes an assumption for it. Other browsers serialize the output, and because the method is "html", they assume it's text/html. If you use "xml", Opera will render the page as XHTML too, while IE will show the resulting XML tree.Most of the other serialization option don't make any difference in the rendering you see in the browser, but they all make a difference in how the source code looks. Do the transformation server side, and you'll see.

Link to comment
Share on other sites

Place both instances in the XHTML namespace, and that is what should happen.And in your code, you have an extra "/" when you declare the root template. It should be:

<xsl:output method="html" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"/><xsl:template match="/"><xsl:value-of select="wcm:root/wcm:element[@name='MyHTMLBlock']/node()" /></xsl:template>

Link to comment
Share on other sites

Thanks!

Place both instances in the XHTML namespace, and that is what should happen.And in your code, you have an extra "/" when you declare the root template. It should be:
<xsl:output method="html" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"/><xsl:template match="/"><xsl:value-of select="wcm:root/wcm:element[@name='MyHTMLBlock']/node()" /></xsl:template>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...