Latest: buggy behaviour of parent:: in PHP 5.3.3

Content with Style

Web Technique

XSL:TEXT, CDATA and PHP5

by Pascal Opitz on October 20 2006, 07:53

Right, so I am applying disable-output-escaping="yes" on an xsl:text element containing some CDATA, but the output is still coming with escaped entities …


<xsl:text disable-output-escaping="yes">
<![CDATA[This is a <p> tag]]>
</xs:text>

This is actually a glitch in the PHP5 built in transformation engine, and the good news is that there is a fix for this. The predefined constant LIBXML_NOCDATA will fix this behaviour to the one you expect:


$xsl_dom->loadXML($xsl, LIBXML_NOCDATA);
or
$xsl_dom->load($xsl_file_location, LIBXML_NOCDATA);

Comments

  • If you want to create tag you must! use xsl:element.

    by Solid on October 22 2006, 23:19 - #

  • Hi Solid. As you can see in my example I CAN do it differently. You CAN even just do something like writing the tags in between XSL commands as well, which probably the most common way to create tags in XSL. Personally I don't believe in MUST when it comes to websites, apart from making the website work as such. The behaviour of PHP5 is a quirk that is in contrast to other rendering behaviours (e.g. Sablotron) and what one uses it for is down to ones needs, no? In my particular case I have a 2 level rendering behaviour in which a transformation creates an XSL document. I want the markup created by the first transformation not being changed by the second one, hence it gets wrapped into xsl:text and CDATA, with disable-output-escaping turned on. This is in order to prevent the second transformation from doing things like changing <div></div> into <div /> ...

    by Pascal Opitz on October 23 2006, 03:08 - #

  • Creepy,
    I just ran into this the other day. I found it a bit awkward that I told it to disable the output escaping… and it straight up didn’t.

    by Dustin Diaz on October 25 2006, 01:54 - #

  • Note that “disable-output-escaping” is generally (though not always) considered harmful, to the extent that it has been removed from XSLT 2. Michael Kay and Wendell Piez have some good views on d-o-e use and abuse in the XSLT FAQ: see http://dpawson.co.uk/xsl/sect2/N2215.html#d3496e130

    by Nick Fitzsimons on October 29 2006, 10:51 - #

  • Oh, one more thing: I’ve just noticed that you say in comment 2 that you want to “prevent the second transformation from doing things like changing <div></div> into <div />”. If the second transformation uses <xsl:output method=”html”>, you should get what you want without having to muck about with d-o-e.

    by Nick Fitzsimons on October 29 2006, 10:57 - #

  • Hi Nick, thanks for the info … what if you specify the output method html, then the transformation doesn’t get you valid XHTML 1 … xhtml is an xml aplication, but the quirks like <div /> break websites in IE 6 … what to do, what to do?

    by Pascal Opitz on October 29 2006, 12:21 - #

  • To be honest, I’ve just accepted the fact that, for as long as the dominant browser doesn’t support XHTML, there’s no point using it :-(

    I serve HTML (on the sites I produce for clients, I haven’t yet hacked WordPress to serve HTML on my own site) on the basis that it is the only content type that is properly supported in the real world. As I’m generating the markup using XSLT, it will be an easy matter at a later date to start serving XHTML: a change to the relevant parts of <xsl:output> – that is, doctype-public, doctype-system and method – is all that will be required. But until XHTML 1 is supported to the same extent as HTML 4.01, it makes more sense (to me) to serve HTML. It’s still a standard, after all :-)

    It’s perhaps worthy of note in this context that Tim Berners-Lee this week said that “The attempt to get the world to switch to XML, including quotes around attribute values and slashes in empty tags and namespaces all at once didn’t work” when he announced a new W3C initiative to develop HTML further, rather than concentrating solely on XHTML: see http://dig.csail.mit.edu/breadcrumbs/node/166

    by Nick Fitzsimons on October 29 2006, 12:47 - #

  • Interesting comment by Mr Brenners-Lee … I actually get along quite well with websites served in XHTML and haven’t really encoutered big problems in modern browsers so far, as long as the content type they’re served in is NOT xml. The only thing that really makes problems is self-closing block elements … if they come up then everything breaks.
    haven’t tried this so far: Would a transformation with output type “html” and XHTML doctypes produce valid XHTML? Or would the type need to be changed to “xml” in order to get self closing image tags etc?

    by Pascal Opitz on October 30 2006, 02:41 - #

Leave your comment

Comments are moderated.
Tags allowed: a, strong, em, code, ul, ol, li, q, blockquote, br, p

Advertisement
Advertisement