Question

I'm having an issue that I just can't seem to figure out. I built a website not too long ago in HTML and have recently integrated Symphony CMS and have had to change everything to XML.

Originally in my head, I had a internet explorer specific stylesheet, the head looked something like this:

<head>
       <link rel="stylesheet" href="../css/master.css" type="text/css" media="screen"></link>
       <!--[if IE]>
             <link rel="stylesheet" type="text/css" href="../css/ie.css"></link>
             <script src="../js/html5shiv.js"></script>
       <![endif]-->
</head>

Since switching, this conditional comment does no longer work, I've changed it to this but unfortunately, my master.css is getting ignored for Chrome/Firefox etc... It is just loading the ie.css stylesheet for all browsers.

<head>
    <link rel="stylesheet" href="../css/master.css" type="text/css" media="screen"></link>                
    <xsl:comment>[if IE]<![CDATA[><!]]></xsl:comment>
          <link rel="stylesheet" type="text/css" href="../css/ie.css"></link>
          <script src="../js/html5shiv.js"></script>
    <xsl:comment><![CDATA[<!]]>[endif]</xsl:comment>    
</head>

Sorry I'm fairly new at this and I'm just not sure what I'm doing wrong, I'm guessing I might need some sort of xsl:if comment but just not sure how to go about it really. I just need something that will make chrome/firefox/opera/safari ignore the ie.css stylesheet.

Any help would be greatly appreciated! Thanks

Was it helpful?

Solution

Just use one xsl:comment and wrap all of the contents in <![CDATA[]]>...

    <head>
        <link rel="stylesheet" href="../css/master.css" type="text/css" media="screen"></link>
        <xsl:comment><![CDATA[[if IE 6]>
         <link rel="stylesheet" type="text/css" href="../css/ie.css"></link>
         <script src="../js/html5shiv.js"></script>
   <![endif]]]></xsl:comment>
    </head> 

OTHER TIPS

Use a template to allow conditional comments to be defined programmatically:

<xsl:template name="conditionalComment">
    <xsl:param name="qualifier" select="'IE'"/>
    <xsl:param name="contentRTF" select="''" />


    <!--Use entity variables to allow invalid XML output from an XSLT processor-->
    <xsl:comment>[if <xsl:value-of select="$qualifier"/>]<![CDATA[>]]>
    <!--Use copy-of rather than value-of to preserve tag delimiters-->
        <xsl:copy-of select="$contentRTF" />
    <!--Use CDATA to output raw characters-->
        <![CDATA[<![endif]]]></xsl:comment>

</xsl:template>

The template takes two parameters:

<xsl:call-template name="conditionalComment">
    <!--Conditional check parameter-->
    <xsl:with-param name="qualifier" select="'lte IE 6'"/>
    <!--Stylesheet parameter-->
    <xsl:with-param name="contentRTF">
        &lt;link rel="stylesheet" type="text/css" href="ie-win-fixup.css" /&gt;
    </xsl:with-param>
</xsl:call-template> 

References

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top