0

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: localhost:// phpinfo()

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.

Community
  • 1
  • 1
danjah
  • 2,939
  • 2
  • 30
  • 47
  • 1
    Are they different operating Systems? I've seen similar differences using IBM JRE on Windows compared to IBM JRE running on OS/400 – Harry Lime Jun 20 '11 at 13:03
  • Yes indeed, Linux hosted, Windows local... – danjah Jun 20 '11 at 13:06
  • 1
    Can you give an example of the XML being input to the transformation? – Harry Lime Jun 20 '11 at 13:17
  • Yep - its http://codefinger.co.nz/_testing/build_2011/xml/siteContent.xml – danjah Jun 21 '11 at 00:05
  • I've tried to do the transformation (in Java admittedly) on Windows and on Unix. I get the same result `
    ` `

    An item.

    ` `
    ` Is this the part that you're having trouble with?
    – Harry Lime Jun 21 '11 at 09:59
  • If it failed, like it did for me on the Linux server, then you will get 2 Javascript errors because CDATA escapes have been inserted by the transform (or the browser?) after each inline Javascript block. The errors are parsing errors, because the CDATA escapes are not read as such, they're parsed as... Javascript. I should re-iterate, there is *no* escaping of mine going on here, except for the "" before any script text inside the blocks. Its very odd. Thanks for continuing to look at this, its doing my head in! – danjah Jun 21 '11 at 10:24
  • 1
    How about using `CDATA` sections in the xsl? Like this: `<![CDATA[ ..... ]]>` – Harry Lime Jun 21 '11 at 11:19
  • Yeah that nearly worked perfectly! Only one thing - a > symbol has been replaced by a character entity (>): var carousel = new Y.Carousel({ boundingBox: "#group-0", contentBox: "#group-0 > ol" }); How can I avoid this, and will anything else be replaced in such a way? Its not a huge problem, I can totally move that carousel stuff into an external script already being loaded (pageload.js) but if I can just stop any funky replacement, that's a solid result. – danjah Jun 21 '11 at 11:36
  • Oh, ack, that didn't work on live server - live server didn't replace the > symbol, but also continued with the parse errors - just clear cache and refresh that URL above to see the result :/ – danjah Jun 21 '11 at 11:40
  • Ok dude - I finally got it, combined with your insertion of CDATA sections, I wrapped the script block contents in tages, as suggested here: http://support.microsoft.com/kb/273793 . Combined, everything seems to work just fine. Add the CDATA as an answer and I'll give you a big green tick - thanks again. – danjah Jun 21 '11 at 11:50

1 Answers1

2

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>
Harry Lime
  • 29,476
  • 4
  • 31
  • 37