一段XSLT转换的代码,主要目的是实现动态表单时取XML节点名
也懒得说原理了。大家应该看得懂吧
<html>
<head>
<script>
function test2()
{
// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.loadXML(t1.value)
// Load the XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.loadXML(t2.value)
// Transform
var sss=xml.transformNode(xsl);
document.getElementById("mydiv").innerHTML=sss;
}
</script>
</head>
<body>
<input type=button οnclick="test2()" value="show content">
<div id="mydiv" style="boder:solid 1px red;"></div>
<textarea id="t1" cols="100" rows=20>
<?xml version="1.0" ?>
<Forms>
<Process name="Test1" dept="环保局" date="2011-1-1">
<Form>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</Form>
</Process>
<Process name="用地审批" dept="国土" date="2011-2-1">
<Form>
<TITLE>Hello</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</Form>
</Process>
</Forms>
</textarea>
<textarea id="t2" cols="100" rows=20>
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="/Forms/Process">
<table border="1" style="border:solid 1px red; width:98%;margin:5px;">
<tr>
<th width="200px"><xsl:value-of select="./@name"/></th>
<th width="60%" align="right">发布单位:<xsl:value-of select="./@dept"/></th>
<th>发布日期:<xsl:value-of select="./@date"/></th>
</tr>
<xsl:for-each select="./Form/*">
<tr>
<td><xsl:value-of select="name()"/></td>
<td colspan="2"><xsl:value-of select="."/></td>
</tr>
</xsl:for-each>
</table>
<hr />
</xsl:template>
</xsl:stylesheet>
</textarea>
</body>
</html>