javascript
javascript与xml实例应用
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>
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
轉載于:https://blog.51cto.com/1085616858/847909
總結
以上是生活随笔為你收集整理的javascript与xml实例应用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: wp insert post 插入文章到
- 下一篇: JavaScript制作简易的《飞机大战