Even if I try only to do an identity-copy:
...
I only get the
link-element without the conditional comment around it.
If this is true, which I doubt, then you are using a very buggy XSLT processor. No compliant XSLT processor will strip out a comment and produce the comment text -- without having the appropriate XSLT instructions (within a template matching comment()
).
Of course, I couldn't reproduce this "problem" having tried 6-7 different XSLT processors with this transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output 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:stylesheet>
When applied on this XML document (the comment, wrapped in a single top element to become a well-formed XML document):
<html>
<!--[if lte IE 7]> <link rel='stylesheet' href='ie.css' type='text/css' /> <![endif]-->
</html>
the result is exactly the same XML document:
<html>
<!--[if lte IE 7]> <link rel='stylesheet' href='ie.css' type='text/css' /> <![endif]-->
</html>
Having said that, to generate such a "comment" is a little bit more tricky -- here is a demo how to do this:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/*">
<html>
<xsl:text disable-output-escaping="yes">
<!--[if lte IE 7]> </xsl:text>
<link rel='stylesheet' href='ie.css' type='text/css' />
<xsl:text disable-output-escaping="yes"> <![endif]-->
</xsl:text>
</html>
</xsl:template>
</xsl:stylesheet>
When this transformation is applied to any XML document (not used in our example), the wanted, correct output is produced:
<html>
<!--[if lte IE 7]> <link rel="stylesheet" href="ie.css" type="text/css"/> <![endif]-->
</html>