我如何使用JavaScript来转换XML& XSLT? [英] How can I use JavaScript to transform XML & XSLT?
本文介绍了我如何使用JavaScript来转换XML& XSLT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用JavaScript来显示我的XSLT,但在我的服务器上没有任何内容显示在浏览器中。
I want to use JavaScript to show my XSLT, but on my server nothing is showing up in the browser.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript" src="main.js"></script>
<meta http-equiv="Content-Language" content="en-us"/>
<title>Contracting, Licensing and Compliance News</title>
</head>
<body>
<script language="javascript">
function displayMessage() {
// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load("site-index.xml")
// Load the XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("site-index.xsl")
// Transform
document.write(xml.transformNode(xsl))
}
</script>
</body>
</html>
推荐答案
浏览器可以为您执行转换。不需要javascript,只需链接.xml中的.xsl就像这样:
The browser can perform the tranform for you. No javascript is needed, just link the .xsl from the .xml like this:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="site-index.xsl" ?>
并且只提供xml,没有html。假设您的.xsl包含正确的代码,
and just serve the xml, no html. Assuming your .xsl contains the right code, along the lines
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.01" indent="yes"/>
<xsl:output doctype-system="http://www.w3.org/TR/html4/strict.dtd"/>
<xsl:output doctype-public="-//W3C//DTD HTML 4.01//EN"/>
这篇关于我如何使用JavaScript来转换XML& XSLT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文