• javascript轻松实现调用xslt解析xml


    代码
    <html>
       
    <head>
          
    <title>student</title>
          
    <script language="javascript">
       
    function doRun()
       {
        
    var myXml=new ActiveXObject("Microsoft.XMLDOM");
        myXml.async
    =false;
        myXml.load(
    "hello.xml");
        
    var myXsl=new ActiveXObject("Microsoft.XMLDOM");
        myXsl.async
    =false;
        myXsl.load(
    "hello.xsl");
        
    //document.write(myXml.transformNode(myXsl));
        document.getElementById('divXslt').innerHTML = myXml.transformNode(myXsl);
    }
          
    </script>
       
    </head>
       
    <body>
       
    <input type="button" value="执行" onclick="doRun();"></input>
       
    <div id="divXslt"></div>
       
    </body>
    </html>

    hello.xsl

    hello.xsl
    <?xml version="1.0" encoding="GB2312"?> 
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> 
    <xsl:template match="/"> 
    <html> 
    <head> 
    <title>First XSLT example</title> 
    </head> 
    <body> 
    <table border="1" width="50%">
        
    <tr style="background-color:yellow">
            
    <td>姓名</td>
            
    <td>年龄</td>
        
    </tr>
        
    <xsl:for-each select="PEOPLE/PERSON"> 
        
    <tr>
            
    <td><xsl:value-of select="name"/></td>
            
    <td><xsl:value-of select="age" /></td>
        
    </tr>
        
    </xsl:for-each>
    </table>
    </body> 
    </html> 
    </xsl:template> 
    </xsl:stylesheet> 

    hello.xml

    hello.xml
    <?xml version="1.0" encoding="GB2312"?> 
    <!--<?xml-stylesheet type="text/xsl" href="hello.xsl"?>-->
    <PEOPLE> 
    <PERSON> 
    <name>ajie</name> 
    <age>28</age> 
    </PERSON> 
    <PERSON> 
    <name>tom</name> 
    <age>24</age> 
    </PERSON> 
    <PERSON> 
    <name>miake</name> 
    <age>30</age> 
    </PERSON> 
    </PEOPLE>
  • 相关阅读:
    项目总结升级2
    项目总结升级1
    项目总结升级
    项目总结4
    项目总结3
    体温填报app2.0开发
    每日博客
    第一周开课博客
    学习日报
    学习日报
  • 原文地址:https://www.cnblogs.com/ding0910/p/1773787.html
Copyright © 2020-2023  润新知