Project

Profile

Help

About to Blow My Brains Out Over Output Esc

Added by Anonymous over 17 years ago

Legacy ID: #4375803 Legacy Poster: Jeff (jeff-s)

have not been able to get my HTML re-processed without its <script> contents being escaped (i.e. && becomes &amp;&amp;). TO add to the cofusion I can use StylusStudio to do this easily, using something like: <?xml version='1.0'?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:copy-of select="."/> </xsl:template> </xsl:stylesheet> However, doing the same thing, using the same stylesheet file in Java will cause the output to be escaped. Nothing like CDATA and other processing instructions help. Here's the Java code. THe settings are listed at the bottom. System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl"); StreamSource xsltSource = new StreamSource(new File(args[1])); factory.newTransformer(xsltSource).transform(new StreamSource(args[0]), new StreamResult(System.out)); Here's how the HTML looks like: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Some title</title> <script language='JavaScript' type="text/javascript"><![CDATA[ for (var i=0; i < document.form1.length ; i++){ if (document.form1[i].type == "text" && document.form1[i].value == "" ... Using StylusStudion 2006-release 3 Saxon setting in SS.: all default based on Saxon8.7.1 Eclipse 3.2; JDK1.4.2; Saxon8 jar: not sure about the minor version. I wish the Manifest had the version in it. thanks, jeff


Replies (3)

Please register to reply

RE: About to Blow My Brains Out Over Output E - Added by Anonymous over 17 years ago

Legacy ID: #4375829 Legacy Poster: Michael Kay (mhkay)

Try <xsl:output method="html">. Because you are using the XHTML namespace, an XSLT 2.0 processor will default to using the xhtml output method. XHTML is well-formed XML, so the ampersand has to be escaped. Using cdata-section-elements="xhtml:script" might help as well. Michael Kay

RE: About to Blow My Brains Out Over Output Esc - Added by Anonymous over 17 years ago

Legacy ID: #4375897 Legacy Poster: Jeff (jeff-s)

Applied the xsl:output. No difference. Added cdata-section as well to no avail. Again, I must say that the whole thing works perfectly when executed from Stylus but not from Java. I have posted the outputs below. Note the &amp;&amp; versus && Kind of Good News: Removing the DOCTYPE from the html file solves the problem (this is what Michael Kay mentioned). But I needed this declaration. So i'm going to remove it from my input HTMLs but add then to the xsl:output tag. I'm still puzzled at the difference between SS and my own code. *** Updated StyleSheet *** <?xml version='1.0'?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml"> <xsl:output method="html" cdata-section-elements="xhtml:script"/> <xsl:template match="/"> <xsl:copy-of select="."/> </xsl:template> </xsl:stylesheet> **** OUTPUT from StylusStudio using Saxon8.7 **** <html xmlns="http://www.w3.org/1999/xhtml&quot;&gt;&lt;head&gt;&lt;meta http-equiv="Content-Type" content="text/html"><link href="css/styles.css" type="text/css" rel="stylesheet"><script xml:space="preserve" type="text/javascript"> function test() { if(document && window) { // do nothing ; just for test purposes } } </script></head><body> <h1>Hello</h1> </body></html> ***** OUTPUT from Java -- See the original post for config ***** <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" href="css/styles.css" type="text/css"></link><script type="text/javascript" xml:space="preserve"> function test() { if(document &amp;&amp; window) { // do nothing ; just for test purposes } } </script></head> <body> <h1>Hello</h1> </body> </html>

RE: About to Blow My Brains Out Over Output E - Added by Anonymous over 17 years ago

Legacy ID: #4376008 Legacy Poster: Michael Kay (mhkay)

The DTD for XHTML contains an implicit namespace declaration that puts all the elements in the XHTML namespace. I guess that Stylus Studio is configuring the XML parser somehow so that the DTD isn't applied. The HTML output method treats the script element specially, but only if it is in no namespace. If you force the data into no-namespace, like this: <?xml version='1.0'?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:template match=""> <xsl:element name="{local-name()}"> <xsl:copy-of select="@"/> <xsl:apply-templates/> </xsl:element> </xsl:template> </xsl:stylesheet> then the && is output unescaped. Michael Kay

    (1-3/3)

    Please register to reply