xsl文件:js_xml.xsl
 

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
   <html>
      <body>
         <table>
            <tr>
               <td>商品编号</td>
               <td>商品名称</td>
               <td>商品类别</td>
               <td>商品价格</td>
            </tr>
            <xsl:for-each select="shop/product">
            <tr>
               <td><xsl:value-of select="id"></xsl:value-of></td>
               <td><xsl:value-of select="name"></xsl:value-of></td>
               <td><xsl:value-of select="leibie"></xsl:value-of></td>
               <td><xsl:value-of select="price"></xsl:value-of></td>
            </tr>
           </xsl:for-each>
         </table>
      </body>
   </html>
</xsl:template>
</xsl:stylesheet>

xml文件:js_xml.xml

<?xml version="1.0" encoding="utf-8"?>
<shop>
   <product>
      <id>00001</id>
   <name>铅笔</name>
   <leibie>文具</leibie>
   <price>11</price>
   </product>
    <product>
      <id>00002</id>
   <name>裙子</name>
   <leibie>服装</leibie>
   <price>77</price>
   </product>
    <product>
      <id>00003</id>
   <name>裤子</name>
   <leibie>服装</leibie>
   <price>55</price>
   </product>
    <product>
      <id>00004</id>
   <name>牙膏</name>
   <leibie>生活用品</leibie>
   <price>6.5</price>
   </product>
    <product>
      <id>00005</id>
   <name>牙刷</name>
   <leibie>生活用品</leibie>
   <price>2.5</price>
   </product>
</shop>

js文件:js_xml.js

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<script language="javascript">
  var xml=new ActiveXObject("Microsoft.XMLDOM")
  xml.async=false
  xml.load("js_xml.xml")
  var xsl=new ActiveXObject("Microsoft.XMLDOM")
  xsl.async=false
  xsl.load("js_xml.xsl")
  document.write(xml.transformNode(xsl))
</script>
</body>
</html>