[xsl] XSLT in IE (MSXML3)

Subject: [xsl] XSLT in IE (MSXML3)
From: "Manfred Staudinger" <manfred.staudinger@xxxxxxxxx>
Date: Mon, 25 Jun 2007 17:08:13 +0200
Hi list,

I've written a summary what problems may arise when using
client side XSLT with IE. Tested with IE6 and MSXML3 on
Win2000, it has the form of a stylesheet, to make it ease to
test on different platforms, browser levels and versions of
MSXMLx. Any comments or additions are most welcome!

Regards, Manfred

XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="Test_IE_view.xsl" type="text/xsl"?>
<doc xmlns="http://www.w3.org/1999/xhtml";>
	<p><span>**no*</span><span>*blank**</span></p>
	<p>text1<br/>text2</p>
	<div style="display: none"/>
</doc>

XSLT:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
	xmlns="http://www.w3.org/1999/xhtml";
	xmlns:xhtml="http://www.w3.org/1999/xhtml";
	exclude-result-prefixes="xhtml"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output method="xml"
	doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";
	doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
	encoding="UTF-8" omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="node() | @*">
	<xsl:copy>
		<xsl:apply-templates select="node() | @*"/>
	</xsl:copy>
</xsl:template>

<xsl:template match="xhtml:doc">
<html>
<xsl:comment>in IE-6 below is the same for xsl:output method="xml" or
"html"</xsl:comment>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<title>Testing XSLT in IE (MSXML3)</title>
	<style type="text/css">
#div11, #div12 {background: red; width: 200px; height: 6px; border:
4px solid black; overflow:hidden;}
#div11 {border-width: 6px 40px;}
#div12 {border-width: 6px 0px;}
	</style>
</head>
<body>
	<h2>Testing XSLT in IE (MSXML3)</h2>
	<p>As IE strips whitespace before the XSLT processing starts, it may be worth
		to consider &lt;xsl:strip-space elements="*"/> for a cross-browser
stylesheet.</p>
	<p>IE seems to ignore xsl:output encoding="UTF-8" and produces
		&lt;?xml version="1.0" encoding="UTF-16"?> for the xml header (maybe
		without negative consequences).</p>
	<div id="div11"></div>
	<p>same length for quirks-mode (for xsl:output method="xml" and
omit-xml-declaration
		ommited or ="no")</p>
	<div id="div12"></div>
	<p>Using xsl:output method="html" or "xml" seems to make no difference for the
		following tests. First, the elements come from the <b>input document</b>:
		<ul>
			<li>with xsl:output  indent="yes"  CRLF (hex 0D0A) may be inserted
                               between elements, even in places where
no whitespace was in the
                               source. Strongly recommended:
xsl:output  indent="no"</li>
			<li>the &lt;br/> element becomes &lt;br>CRLF&lt;/br>, giving you an extra
				newline. To eliminate the extra newline you might use &lt;xsl:template
				match="xhtml:br"> &lt;br/> &lt;/xsl:template></li>
			<li>the &lt;div style="display: none"/> becomes &lt;div style="display:
                               none">CRLF&lt;/div></li>
		</ul>
	</p>
	<xsl:apply-templates/>
	<p>Second, the elements come from the <b>stylesheet</b>:
		<ul>
			<li>no CRLF (hex 0D0A) will be inserted</li>
			<li>&lt;br/> correctly becomes &lt;br /></li>
			<li>&lt;div style="display: none"/> becomes &lt;div style="display: none" />,
				causing IE to skip all content which comes after it (here
                               &lt;p>text6&lt;/p>). To avoid this,
simply code &lt;div style="display:
                               none">&lt;/div>.</li>
		</ul>
	</p>
	<p><span>**no*</span><span>*blank**</span></p>
	<p>text1<br/>text2</p>
	<div style="display: none"></div>
	<p>text5</p>
	<div style="display: none"/>
	<p>text6</p>
</body>
</html>
</xsl:template>

<xsl:template match="/">
	<xsl:apply-templates select="xhtml:doc"/>
</xsl:template>

</xsl:stylesheet>

Current Thread