Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

client side xslt with javascript in firefox

I am using client-side xslt to transform xml files into xhtml. There have been some hurdles but I have managed to get passed all of them except this.

The problem is that when I have a simple xml file like this

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="./jsInFf.xsl"?>
<root>hello</root>

and transform it to xhtml with a simple xsl like this

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xhtml="http://www.w3.org/1999/xhtml"
  xmlns="http://www.w3.org/1999/xhtml">

  <xsl:output method="xml"
  version="1.0"
  encoding="ISO-8859-1"
  indent="yes"
  omit-xml-declaration="no"
  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 xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <title>a title</title>
        <script type="text/javascript">
          alert(document);
          alert(document.anchors);
    </script>
      </head>
      <body>
        <xsl:value-of select="." /> world
      </body>
    </html>
  </xsl:template>    
</xsl:stylesheet>

the first alert will pop-up as "[object XMLDocument]" with firefox instead of "[object]" like it does for IE and safari. From what I gather this means that firefox does no produce a javascript html document (or html dom, not sure what the wording is). The second alert in firefox will be "undefined" but in IE and safari it is "[object].

So in firefox there is no document.forms or document.anchors etc. I know some javascript will still work, like document.getElementById, but I am afraid that more advanced stuff like ajax will not work propery if document.forms and the like do not exist.

Is there a work-around for this? On my current project I am rewriting a bunch of pages to use xslt. There is a lot of javascipt already writen and changing it all to use the limited firefox javascript is not really an option if it is even possible.

Thank you very much for any help.


1 Answers

1) Fixing your problem

Solving your issue is as simple as changing value of the @method attribute from "xml" to "html" on xsl:output element.

2) Explaining the difference

HTML DOM extends core XML DOM interfaces. So, for example, the collection "forms" is not present in the XMLDocument, but is in HTMLDocument

like image 76
Sergey Ilinsky Avatar answered Feb 13 '26 16:02

Sergey Ilinsky