xml:
<?xml version="1.0" encoding="gb2312"?>
<items>
<item id="1">one</item>
<item id="2">two</item>
<item id="3">three</item>
</items>
xsl:
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<table cellspacing="1" bgcolor="#aaaaaa">
<xsl:apply-templates select="items"/>
</table>
</xsl:template>
<xsl:template match="items">
<xsl:for-each select="item">
<tr><td bgcolor="#eeeeee"><xsl:value-of select="./@id"/></td><td bgcolor="#eeeeee"><xsl:value-of select="."/></td></tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
IE下的转换:
<html>
<head>
<script>
var xmlDom=new ActiveXObject("MSXML2.DOMDocument");
function window.onload(){
xmlDom.async="false";
xmlDom.onreadystatechange=transformXml;
xmlDom.load("test.xml");
}
function transformXml(){
if (xmlDom.readyState != 4) return;
var xslDom=new ActiveXObject("MSXML2.DOMDocument");
xslDom.async="false";
xslDom.load("test.xsl");
document.getElementById("test").innerHTML=xmlDom.transformNode(xslDom);
}
</script>
</head>
<body>
<div id="test"></div>
</body>
</html>
Firefox下:
<html>
<head>
<script>
var xmlDom=new XMLHttpRequest();
var xslDom=new XMLHttpRequest();
var xslTrans = new XSLTProcessor();
window.onload=function(){
xmlDom.open("GET","test.xml",false);
xmlDom.send(null);
var coDoc=xmlDom.responseXML;
xslDom.open("GET", "xsl.xml",false);
xslDom.send(null)
var mydoc=xslDom.responseXML;
xslTrans.importStylesheet(mydoc);
var frag=xslTrans.transformToFragment(coDoc,document);
document.getElementById("test").appendChild(frag);
}
</script>
</head>
<body>
<div id="test"></div>
</body>
</html>
<?xml version="1.0" encoding="gb2312"?>
<items>
<item id="1">one</item>
<item id="2">two</item>
<item id="3">three</item>
</items>
xsl:
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<table cellspacing="1" bgcolor="#aaaaaa">
<xsl:apply-templates select="items"/>
</table>
</xsl:template>
<xsl:template match="items">
<xsl:for-each select="item">
<tr><td bgcolor="#eeeeee"><xsl:value-of select="./@id"/></td><td bgcolor="#eeeeee"><xsl:value-of select="."/></td></tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
IE下的转换:
<html>
<head>
<script>
var xmlDom=new ActiveXObject("MSXML2.DOMDocument");
function window.onload(){
xmlDom.async="false";
xmlDom.onreadystatechange=transformXml;
xmlDom.load("test.xml");
}
function transformXml(){
if (xmlDom.readyState != 4) return;
var xslDom=new ActiveXObject("MSXML2.DOMDocument");
xslDom.async="false";
xslDom.load("test.xsl");
document.getElementById("test").innerHTML=xmlDom.transformNode(xslDom);
}
</script>
</head>
<body>
<div id="test"></div>
</body>
</html>
Firefox下:
<html>
<head>
<script>
var xmlDom=new XMLHttpRequest();
var xslDom=new XMLHttpRequest();
var xslTrans = new XSLTProcessor();
window.onload=function(){
xmlDom.open("GET","test.xml",false);
xmlDom.send(null);
var coDoc=xmlDom.responseXML;
xslDom.open("GET", "xsl.xml",false);
xslDom.send(null)
var mydoc=xslDom.responseXML;
xslTrans.importStylesheet(mydoc);
var frag=xslTrans.transformToFragment(coDoc,document);
document.getElementById("test").appendChild(frag);
}
</script>
</head>
<body>
<div id="test"></div>
</body>
</html>