gpt4 book ai didi

javascript - 在 Firefox 中使用 JavaScript 的客户端 xslt

转载 作者:行者123 更新时间:2023-11-29 10:25:49 24 4
gpt4 key购买 nike

我正在使用客户端 xslt 将 xml 文件转换为 xhtml。有一些障碍,但除了这个,我已经设法通过了所有障碍。

问题是当我有一个像这样的简单 xml 文件时

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

并使用像这样的简单 xsl 将其转换为 xhtml

<?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>

第一个警报将弹出为“[object XMLDocument]”,使用 firefox 而不是像 IE 和 safari 那样的“[object]”。据我所知,这意味着 firefox 不会生成 javascript html 文档(或 html dom,不确定措辞是什么)。 Firefox 中的第二个警报是“未定义”,但在 IE 和 Safari 中是“[object]”。

所以在 firefox 中没有 document.forms 或 document.anchors 等。我知道一些 javascript 仍然可以工作,比如 document.getElementById,但我担心如果 document.forms 和类似的不存在。

有解决办法吗?在我当前的项目中,我正在重写一堆页面以使用 xslt。已经编写了很多 javascipt,如果可能的话,将其全部更改为使用有限的 firefox javascript 并不是一个真正的选择。

非常感谢您的帮助。

最佳答案

1) 解决你的问题

解决您的问题非常简单,只需将 xsl:output 元素上的 @method 属性的值从“xml”更改为“html”即可。

2) 解释差异

HTML DOM 扩展了核心 XML DOM 接口(interface)。因此,例如,集合“forms”不存在于 XMLDocument 中,但存在于 HTMLDocument 中

关于javascript - 在 Firefox 中使用 JavaScript 的客户端 xslt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1051529/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com