Susheel Singh
Susheel Singh

Reputation: 3854

how to get dynamic values inside a xsl:comment

This below code doesnot load the dynamic value of $URL_PREFIX as it is in cdata. Please let me know how to get dynamic values inside a comment.

    <xsl:comment><![CDATA[[if gte IE 9]>    
        <link href="$URL_PREFIX/Static/resources/common/css/redesign/new-ie.css" rel="stylesheet" type="text/css" />
    <![endif]]]></xsl:comment>

I want the value $URL_PREFIX.

Upvotes: 0

Views: 300

Answers (1)

Daniel Haley
Daniel Haley

Reputation: 52888

I think you'll need to break up your CDATA like this...

    <xsl:comment><![CDATA[[if gte IE 9]>   
    <link href="]]><xsl:value-of select="$URL_PREFIX"/><![CDATA[/Static/resources/common/css/redesign/new-ie.css" rel="stylesheet" type="text/css" />
<![endif]]]></xsl:comment>

Full example...

XSLT 1.0 (applied to any XML input)

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="/">
        <xsl:variable name="URL_PREFIX" select="'http://foo.com'"/>
        <xsl:comment><![CDATA[[if gte IE 9]>   
        <link href="]]><xsl:value-of select="$URL_PREFIX"/><![CDATA[/Static/resources/common/css/redesign/new-ie.css" rel="stylesheet" type="text/css" />
    <![endif]]]></xsl:comment>
    </xsl:template>

</xsl:stylesheet>

Output

<!--[if gte IE 9]>   
        <link href="http://foo.com/Static/resources/common/css/redesign/new-ie.css" rel="stylesheet" type="text/css" />
    <![endif]-->

Upvotes: 1

Related Questions