XSLT disable-output-escaping not holding across tw

2019-09-05 05:00发布

问题:

Gidday,

I have a page with XSLT doing small amounts of awesome, and it has mostly been going quite well, but I've hit a roadblock.

This page: http://codefinger.co.nz/_testing/build_2011/ chokes on CDATA sections that aren't actually in part of my .xsl file, they seem to be inserted during transformation (Javascript parse errors thrown).

Interestingly, this SO question: xslt, javascript and unescaped html entities solved the problem on my local test site (I wrapped the contents of my script blocks with the disable-output-escaping XSL tags), which is a WAMP 2.0 stack with this XSL config:

My live, hosted server has this config: http://codefinger.co.nz/php-info.php, and this same approach does not work.

Here's the source .xsl file: http://codefinger.co.nz/_testing/build_2011/xsl/siteContent.xsl, the associated .xml is valid, it is here: http://codefinger.co.nz/_testing/build_2011/xml/siteContent.xml.

Any ideas?

It should be noted that I really don't fancy moving 2 of the 3 scripts blocks to external files - one is Cufon font replacement (so I could move it), the other is a wee script in the head tag by Luke Smith, which is converted to CSS when JS is available.

回答1:

Use CDATA sections in your <xsl:text> elements Like this:

<xsl:text disable-output-escaping="yes"><![CDATA[
    ..... 
]]></xsl:text> 

In the comments above, you found yourself that this is even better:

<xsl:comment><![CDATA[
    ..... 
]]></xsl:comment>