案例:XSL案例     状态:不可编辑再运行    进入竖版
 运行结果 
x
 
1
<html>
2
<body>
3
<script type="text/javascript">
4
function loadXMLDoc(dname)
5
{
6
if (window.XMLHttpRequest)
7
  {
8
  xhttp=new XMLHttpRequest();
9
  }
10
else
11
  {
12
  xhttp=new ActiveXObject("Microsoft.XMLHTTP");
13
  }
14
xhttp.open("GET",dname,false);
15
xhttp.send("");
16
return xhttp.responseXML;
17
}
18
19
xml=loadXMLDoc("/example/xmle/books.xml");
20
path="/bookstore/book[price>35]/price";
21
// code for IE
22
if (window.ActiveXObject)
23
{
24
var nodes=xml.selectNodes(path);
25
26
for (i=0;i<nodes.length;i++)
27
  {
28
  document.write(nodes[i].childNodes[0].nodeValue);
29
  document.write("<br />");
30
  }
31
}
32
// code for Mozilla, Firefox, Opera, etc.
33
else if (document.implementation && document.implementation.createDocument)
34
{
35
var nodes=xml.evaluate(path, xml, null, XPathResult.ANY_TYPE,null);
36
var result=nodes.iterateNext();
37
38
while (result)
39
  {
40
  document.write(result.childNodes[0].nodeValue);
41
  document.write("<br />");
42
  result=nodes.iterateNext();
43
  }
44
}
45
</script>
46
47
</body>
48
</html>