xsl-list
[Top] [All Lists]

Re: The case of the mysteriously corrupted XSL transformation (ARRGH)

2004-12-02 13:46:50
Hi Wong,

I made a simple testcase, that demonstrates Mozilla/Gecko/Transformiix does have a problem with javascript document.write:

=== test.xsl ===

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
 xmlns="http://www.w3.org/1999/xhtml";
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
 >
 <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"
   doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
   doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";
   />
 <xsl:template match="/">
   <html>
     <head><title>test</title></head>
     <body>
       <div>
         <script type="text/javascript">
           document.write('hello');
         </script>
       </div>
     </body>
   </html>
 </xsl:template>
</xsl:stylesheet>

=== input.xml ===

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<dummy/>

=== saxon output.html ===

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html
 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";>
 <head>
   <title>test</title>
 </head>
 <body>
   <div>
     <script type="text/javascript">
       document.write('hello');
     </script>
   </div>
 </body>
</html>

The output.html generated by Saxon works fine in IE6 and Moz (browser says 'hello').

Opening input.xml (ie. transforming via the xml-stylesheet PI) works fine in IE6 too, but not in Firefox: blank page, and javascript error: "document.write is not a function".

(Firefox 1.0 and Netscape 7.2 show the same result)

I don't know if this is "normal", or a Mozilla/Gecko bug... I think it should work - I have used methods like appendChild succesfully, why should document.write fail here? Maybe some other xslister can elaborate...

Best regards,
Anton




Wong Chin Shin wrote:

Hi Anton,

Thanks for the help.

I see what you mean, but can I clarify:

Is it true that "on-the-fly" Javascript like document.write will have
problems working in an XSL-transformed page? I had the impression that the
transformation layer is just an additional layer and that the browser would
consider the final code only. If this is the case, a lot of existing scripts
would be off-limits to whoever's trying to employ this technique.

Also, the fact that it works using some XSL parsers and not with others is a
worry. I just hope that I'm doing things according to specs so far and the
next server upgrade won't break it.

Thanks!
Wong


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--