Sign In/My Account | View Cart  
advertisement

Article:
 XSLT, Browsers, and JavaScript
Subject: Watch out with output escaping...
Date: 2003-03-20 18:00:26
From: Frederik Willaert

Hello,


A "caveat" I ran into when producing JavaScript with XSLT...


As you may have read in the thread about "CDATA", you can simply write e.g. "<" in order to get "<" in the JavaScript output. However, it appears that this only works correctly when the output method is set to "html", either by:


- explicitly setting the output method to "html" on the <xsl:output> element
- making sure that the output document has <html> as its root element, and either there is no <xsl:output> element in your stylesheet, or it has the value "html" - in this case, the XSLT processor defaults to the html output method, as the XSLT spec explains.


Either way, output escaping is only disabled for the content of the <script> and <style> tags (again, see the XSLT spec, http://www.w3.org/TR/xslt#section-HTML-Output-Method).


If you _have_ to use the xml output method, an alternative is to use <xsl:text disable-output-escaping="yes">, but this soon gets messy.


I've been experimenting a bit with the different possibilities (using MSXML4.0, by the way), but I still may have missed something - tell me. I should read that XSLT spec a bit more thoroughly, I guess...


Frederik Willaert


PS. I know this post has something to do with the CDATA thread, but I thought this could be considered as a separate topic...


Previous Message Previous Message   Next Message Next Message


Sponsored By: