客户端XSLT与JavaScript在Firefox中 [英] client side xslt with javascript in firefox
问题描述
我使用客户端xslt将xml文件转换为xhtml。有一些障碍,但我已经设法通过所有这些除了这一点。
问题是,当我有这样一个简单的XML文件
<?xml version =1.0encoding =ISO-8859-1?>
<?xml-stylesheet type =text / xslhref =./ jsInFf.xsl?>
< root> hello< / root>
然后用这个简单的xsl将它转换为xhtml
<?xml version =1.0encoding =ISO-8859-1?>
xmlns:xsl =http://www.w3.org/1999/XSL/Transform
xmlns:xhtml =http: //www.w3.org/1999/xhtml
xmlns =http://www.w3.org/1999/xhtml>
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>标题< / title>
< script type =text / javascript>
alert(document);
alert(document.anchors);
< / script>
< / head>
< body>
< / body>
< / html>
< / xsl:template>
< / xsl:stylesheet>
第一个警报将弹出为[object XMLDocument],而不是[object ]就像IE和safari一样。从我收集这意味着Firefox不会产生一个JavaScript HTML文档(或HTML DOM,不知道什么是措辞)。在Firefox中的第二个警报将是未定义的,但在IE浏览器和Safari浏览器是[object]。
所以在Firefox中没有document.forms或document.anchors等我知道一些JavaScript仍然会工作,如document.getElementById,但我担心更高级的东西,如Ajax不会工作propery如果document.forms等不存在。
有没有解决这个问题的方法?在我当前的项目中,我正在重写一堆页面以使用xslt。已经有很多javascipt已经写入并且将其全部更改为使用有限的Firefox。
非常感谢您的帮助。
<2>解释差异
HTML DOM扩展了核心XM L DOM接口。所以,例如,集合forms不在XMLDocument中,而是在HTMLDocument中。
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) 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
这篇关于客户端XSLT与JavaScript在Firefox中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!