xsl-list
[Top] [All Lists]

Re: IE's conditional comments in xslt

2006-03-05 18:28:09
Thank you for this extended understanding!  Makes a lot of sense, and
can see why you wanted this.

Quick Pointer: A fantastic solution to gaining much of the extended
pieces of the CSS support IE doesnt provide is found in Dean Edwards
[ironically] IE7 project.  You can access this project at
http://dean.edwards.name/IE7/

I use this quite often for a TON of projects and it works quite well. 
One thing to consider: His code base loads after the loading of the
page into the dom is complete.  If any dynamic changes take place that
include these extended capabilities after this event has been fired
(better said, after the page has been loaded) then you need to call:

document.recalc(true)

Beyond this, and a bit of an extra page load time (not noticeable on
lightweight pages... say anything under 25-30K.  Above this, it
becomes proportionately noticeable.) its a FANTASTIC solution.  Highly
recommended. :)

On 3/5/06, Manfred Staudinger <manfred(_dot_)staudinger(_at_)gmail(_dot_)com> 
wrote:
On 04/03/06, M. David Peterson <m(_dot_)david(_at_)mdptws(_dot_)com> wrote:
Setting this portion aside, I am now intrigued to hear about what it is
you are attempting, and how you are proposing to solve this.  I think I
originally assumed too much as to what it seemed to be you were trying
to solve.

This is about generating conditional comments with xslt on client-side.

Every xslt enabled browser has a standard css 2.1 support, except
IE 6, IE 5.5 and IE 5.01. I'm going to discuss here IE 6 only, as the
extensions necessary to serve IE 5.5 or IE 5.01 are straightforward.
It was and is considered good practice to use the following html:

<link rel="stylesheet" href="all_browsers.css" type="text/css" />
<!--[if IE 6]>
   <link rel="stylesheet" href="hacks_for_ie6.css" type="text/css" />
<![endif]-->

But if you really wanted to use for example css 2.1 descendant selectors,
you are at a loss with this model. Without client-side xslt, the only
solution is to use server-side processing to deliver
a) for non-IE browsers plus IE 7
<link rel="stylesheet" href="css_2_1_browsers.css" type="text/css" />
a) for IE browsers except IE 7
<link rel="stylesheet" href="all_browsers.css" type="text/css" />
<!--[if IE 6]>
   <link rel="stylesheet" href="hacks_for_ie6.css" type="text/css" />
<![endif]-->

For the xslt enabled browser, you can do exactly the same with this
client-side xslt:
<xsl:comment><![CDATA[[if IE]><![if IE 7]><![endif]]]></xsl:comment>
        <link rel="stylesheet" href="css_2_1_browsers.css" type="text/css" />
<xsl:comment><![CDATA[[if IE]><![endif]><![endif]]]></xsl:comment>
<xsl:if test="system-property('xsl:vendor')='Microsoft'">
        <xsl:comment><![CDATA[[if IE]><![if lte IE 
6]><![endif]]]></xsl:comment>
                <link rel="stylesheet" href="all_browsers.css" 
type="text/css" />
        <xsl:comment><![CDATA[[if IE]><![endif]><![endif]]]></xsl:comment>
        <xsl:comment><![CDATA[[if IE]><![if IE 6]><![endif]]]></xsl:comment>
                <link rel="stylesheet" href="hacks_for_ie6.css" 
type="text/css" />
        <xsl:comment><![CDATA[[if IE]><![endif]><![endif]]]></xsl:comment>
</xsl:if>

An other example would be to add a div element to the body to simulate
position fixed for IE 5.5 and IE 5.01. You should note also that all the
"conditional" html gets parsed and is subject to the normal xslt transform.

Thinking about David's example and why I did not even try that.
When I use (browser-side, IE 6, MSXML 3):
         <xsl:comment>[if IE 6]>
         <style type="text/css">
           h1 {color: red}
         </style>
         &lt;![endif]</xsl:comment>
nothing happened; Saxon 6.5.4 gives the explanation: Recoverable error,
Non-text output nodes are ignored when writing an attribute, comment, or PI.

So back to David's example (simplified here) again, adding CDATA and
changing &lt to < (browser-side, IE 6, MSXML 3):
         <xsl:comment><![CDATA[[if IE 6]>
         <style type="text/css">
           h1 {color: red}
         </style>
         <![endif]]]></xsl:comment>
and now it works! So IE 6 created an element node out from CDATA-text,
this seems to me to be a non-conformant behaviour.

Manfred

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--
<M:D/>

M. David Peterson
http://www.xsltblog.com/
<Prev in Thread] Current Thread [Next in Thread>