Altova Mailing List Archives


Re: [xsl] IE's conditional comments in xslt

From: Chris Burdess <d09@------->
To:
Date: 3/3/2006 9:50:00 PM
Manfred Staudinger wrote:
I would like to propose a xslt conform solution for Conditional
Comments

The proposed solution uses two downlevel-hidden CC's
<!--[if expression]> HTML <![endif]--> and one downlevel-revealed CC
<![if expression]> HTML <![endif]> and consists of:
1. the test for the system-property, to make sure that only MS's IE
will see it.
2. two xslt comment elements with the conditional html in between
3. each one of the xslt comment elements has text inside, which
starts with
"[if IE]>" and ends with "&lt;![endif]", forming a downlevel-hidden
CC.
4. inside the downlevel-hidden CC's there is the start "&lt;![if
lte IE 6]>" and
the end "&lt;![endif]>" of the downlevel-revealed CC.

<xsl:if test="system-property('xsl:vendor')='Microsoft'">
<xsl:comment><xsl:text>[if IE]>&lt;![if lte IE
6]>&lt;![endif]</xsl:text></xsl:comment>
	<!-- "lte IE 6" = "expression" -->
	<!-- html gets executed by any IE for which the "expression" is
true -->
<xsl:comment><xsl:text>[if
IE]>&lt;![endif]>&lt;![endif]</xsl:text></xsl:comment>
</xsl:if>

The only variable part in this example is "lte IE 6", which I'll call
"expression for
this discussion. If the "expression" is true for your browser, the the
html between
those two comments get executed. In the example given, its true for
IE 6, IE 5.5
and IE 5.0, but not for IE 7. To select for IE 6 only, use "IE 6"
and so on.

Browser sniffing for the noughties, how delightful.
--
g
, Chris Burdess
  "They that can give up essential liberty to obtain a little safety
  deserve neither liberty nor safety." - Benjamin Franklin

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.