You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Dave Brosius <db...@mebigfatguy.com> on 2006/01/12 04:16:38 UTC

xsl generation of cdata sections

I thinking that i'm confused, but i'm having trouble generating a CDATA 
section from an xsl transform

<xsl:template match="/">
    <xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text>
        <xsl:text disable-output-escaping="yes'><xsl:value-of 
select="($myvar)"/></xsl:text>
    </xsl:text disable-output-escaping="yes">]]></xsl:text>
</xsl:template>

etc

this majorly screws up, showing "disable-output-escaping" in the output.

or do i not have to specify the <![CDATA[]]> characters, and they will be 
generated if need be?



Re: xsl generation of cdata sections

Posted by David Bertoni <db...@apache.org>.
Dave Brosius wrote:
> I thinking that i'm confused, but i'm having trouble generating a CDATA 
> section from an xsl transform
> 
> <xsl:template match="/">
>    <xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text>
>        <xsl:text disable-output-escaping="yes'><xsl:value-of 
> select="($myvar)"/></xsl:text>
>    </xsl:text disable-output-escaping="yes">]]></xsl:text>
> </xsl:template>
> 
> etc
> 
> this majorly screws up, showing "disable-output-escaping" in the output.
> 

When the XML parser processes this stylesheet, it reports content for 
everything that's inside of the CDATA section, why are you surprised? 
Remember, a CDATA section tells the parser to treat anything that looks 
like markup within the section as just character data.

> or do i not have to specify the <![CDATA[]]> characters, and they will 
> be generated if need be?
> 

CDATA sections are _never_ necessary -- they're just a way to make a 
document look more human-readable.

As much as I hate perpetuating disable-output-escaping hacks, perhaps 
you meant this:

<xsl:template match="/">
    <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
        <xsl:value-of disable-output-escaping="yes" select="($myvar)"/>
    </xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
</xsl:template>

If that doesn't produce what you're looking for, perhaps you can post a 
complete, minimal sample.  It's often hard to figure out your 
intentions, and what's the real problem from snippets of stylesheets.

You should also take a look at the cdata-section-elements attribute of 
the xsl:output instruction.  If that will work for your case, you should 
use it instead of disable-output-escaping.

Dave