GNOME Bugzilla – Bug 55772
Problem with disabling output escaping
Last modified: 2009-08-15 18:40:50 UTC
I believe there is a problem with disabling output escaping, using <xsl:text disable-output-escaping="yes"><</xsl:text> and in placing < in a <script> element with <xsl:output method="html"/>. This example should explain. ---------- source.xml ---------- <?xml version="1.0"?> <exam name="Midterm Exam" id="TK421" timeLimit="00:30:00" hints="true"> <questions xmlns:xlink="http://www.w3.org/1999/xlink"> <question type="choice" id="TK421-2" instructionId="1"> <questionText>A <emphasis>constant</emphasis> is something that does not change.</questionText> <answers> <answer id="TK421-2-1" correct="true">True</answer> <answer id="TK421-2-2">False</answer> </answers> </question> </questions> </exam> -------------- stylesheet.xsl -------------- <?xml version="1.0" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html"/> <xsl:template match="/"> <html> <head> <title><xsl:value-of select="exam/@name"/></title> <script> <xsl:text disable-output-escaping="yes"><</xsl:text> funtion test() { var a; var b; if (a < b) { alert('Hello'); } } <xsl:text disable-output-escaping="yes"><</xsl:text> </script> </head> <body bgcolor="white"> </body> </html> </xsl:template> </xsl:stylesheet> --------------------- Output using xsltproc --------------------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html> <head> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> <title>Midterm Exam</title> <script>< funtion test() { var a; var b; if (a < b) { alert('Hello'); } } <</script> </head> <body bgcolor="white"></body> </html> -------------------- Good Output Using XT -------------------- <html> <head> <title>Midterm Exam</title> <script>< funtion test() { var a; var b; if (a < b) { alert('Hello'); } } <</script> </head> <body bgcolor="white"> </body> </html> Knowing my luck the output I have pasted here will show up wrong because it envolves entities. There are three instances of < in the stylesheet, but only the first is not escaped in the output.
using libxml2-2.3.10 and libxslt-0.11.0
Thanks for the detailed bug description. I fixed the problem with a small patch to libxml module HTMLtree.c http://cvs.gnome.org/bonsai/cvsquery.cgi?module=gnome-xml&branch=HEAD&branchtype=match&dir=gnome-xml&file=&filetype=match&who=veillard&whotype=match&sortby=Date&hours=&date=explicit&mindate=06%2F05%2F01+16%3A57&maxdate=06%2F05%2F01+16%3A57&cvsroot=%2Fcvs%2Fgnome ----------------------------------------------- orchis:~/XSLT/tests/general -> xsltproc bug-33-.xsl ../docs/bug-33-.xml <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html> <head> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> <title>Midterm Exam</title> <script>< funtion test() { var a; var b; if (a < b) { alert('Hello'); } } <</script> </head> <body bgcolor="white"></body> </html> orchis:~/XSLT/tests/general -> -------------------------------------------------- Daniel
The release of libxml-2.3.11 and libxslt-0.12.0 should close the problem. Daniel