Re: [xsl] Troubles with libxslt in PHP again: CDATA in <script>

Subject: Re: [xsl] Troubles with libxslt in PHP again: CDATA in <script>
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Sat, 13 Oct 2007 16:14:50 +0200
Hi Martynas,

Interesting how you seem to get spooky CDATA's... ;)

I'm using whatever php_xsl.dll extension in PHP 5.2.2 gives. I was sure it's libxslt, and this is what processor-version stylesheet says, not much else though:

XSL version: 1.0
Vendor: libxslt
Vendor URL: http://xmlsoft.org/XSLT/

Thanks for running the stylesheet. Sorry that it didn't work out as expected. However, a little google on "php_xsl.dll libxslt version" shows that with PHP and libxslt you need another method to find out what internal version is being used: phpinfo(). That's only one line in a PHP script and should show you output with something similar to this:


xsl
XSL enabled
libxslt Version 1.1.7
libxslt compiled against libxml Version 2.6.11
EXSLT enabled
libexslt Version 0.8.5

(probably your versions are different, I copied this from some internet site).


or for the oddest reason, your ISP's
HTTP daemon adds them...

Maybe I wasn't clear on this, but I get these problems on my localhost
machine with PHP 5.2.2. The //<xsl:comment> does the trick on it, but
not when I upload to the hosting running PHP 5.2.5.
But still I think that proves that ISP is not the source of the problem.

The only way to find out what it causing your XSLT transformation to behave quite radically different than what it is expected to do, is to try it from the commandline without any external influences.


script code in CDATA since it is by no means finished. And when I'll
add new code, I don't want to think whether there were characters that
should be escaped or not. If it's all in CDATA, it will be escaped
anyway.

I agree. Esp. when you must (or want to) use XHTML.


But I'll tell you what -- it doesn't matter here. I just checked, and
even if I remove all the CDATAs from that template and escape the <
manually into &lt;, in the output I get everything wrapped in CDATA
anyway! And < not escaped in it.

Something starts to dawn here... Have you got, by any chance, a statement similar to the following in your stylesheet?


<xsl:output method="xml" cdata-section-elements="script" />

Because if you do, that's the cause of all your trouble. If you remove that offending attribute, the processor will output &lt; &gt; etc instead of wrapping everything in a CDATA section, even if you use CDATA inside your XSLT stylesheet (recall that XSLT is XML in the first place and that the information on CDATA en entities etc is removed (becomes text nodes) before it gets to the XSLT processor).


Sure I would like to produce XHTML instead, but it doesn't appear to
me that we have come to a solution for doing that.

See above (and some other posts on this list about how to get XHTML with an XSLT 1.0 processor, your biggest fiend not being CDATA, but empty and non-empty tags, actually).


I'll run on commandline when I'll find some time. But still it is not
so clear on what version of libxslt to run.

try phpinfo()


As far as I remember the Content-Type metas issue, I ran my
stylesheets on standalone libxslt as well but got the same results as
with PHP XSL.

That is with method="html". Using method="xml" (or no specification, which will default to html because you start with <html><head> etc) will not output the content types at all.


Cheers,
-- Abel Braaksma

Current Thread