LoginSignup
1
1

More than 5 years have passed since last update.

Google Closure Library On Firefox With XSLT

Last updated at Posted at 2014-01-15

どーゆーこと?

XSLTするならXHTMLで出力するとよい。

Firefox + Closure Library + XSLT + HTML = NOT WORKING!!

次のようなXML文章とXSL文章を組み合わせて、Firefoxで表示すると
Closure Libraryのbase.jsがInvalidStateErrorを出してしまい動かない。

document.xml
<?xml verions="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="html.xsl"?>
<root/>
html.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" indent="yes" encoding="UTF-8" doctype-public="-//W3C//DTD HTML 4.01//EN" doctype-system="http://www.w3.org/TR/html4/strict.dtd"/>

  <xsl:template match="/root">
    <html>
      <head>
        <script src="closure-library/closure/goog/base.js"></script>
      </head>
      <body>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>
InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable

Firefoxはdocument.write & XSLTをサポートしない

Closure Libraryはbase.jsで文書がHTMLの場合にdocument.writeを使っている。
上のようなXSLを使うと、出力はHTMLになるのでClosure Libraryはdocument.writeをこころみる。
しかし、FirefoxはXSLTが絡んだ場合document.writeすることは禁じられていて、実際挙動が不安定になる。
だから、Closure LibraryとHTMLを出力するXSLはそのままでは同時に使用できない。

XHTMLなら万事OK

XHTMLとして出力すれば、Closure Libraryはdocument.writeを使わなくなるので問題なくなる。

document.xml
<?xml verions="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="xhtml.xsl"?>
<root/>
xhtml.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
  <xsl:output method="xml" indent="yes" encoding="UTF-8" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>

  <xsl:template match="/root">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <script src="closure-library/closure/goog/base.js"></script>
      </head>
      <body>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1