当前位置: 代码迷 >> ASP.NET >> 关于XML通过XSL转换为HTML的有关问题
  详细解决方案

关于XML通过XSL转换为HTML的有关问题

热度:9424   发布时间:2013-02-25 00:00:00.0
关于XML通过XSL转换为HTML的问题
C# code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!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 runat="server">    <title></title>    <script type="text/javascript">        function XmlTransactionXSL() {//            alert("ZhangSan");            // Load XML            var xml = new ActiveXObject("Microsoft.XMLDOM")//            alert("ZhangSan1");            xml.async = false;            xml.preserveWhiteSpace = true;                     xml.load("E:\testxsl.xml");//            alert("ZhangSan2");            // Load XSL            var xsl = new ActiveXObject("Microsoft.XMLDOM")            xsl.async = false            xml.preserveWhiteSpace = true;//            alert("ZhangSan3");            xsl.load("E:\testxsl.xsl")//            alert("ZhangSan4");            // Transform            document.write(xml.transformNode(xsl))            alert("ZhangSan5");        }  </script></head><body onload="XmlTransactionXSL()">           <%-- <form id="form1" runat="server">    <div>     TEST    </div>    </form>--%></body></html>


testxsl.xml
XML code
<?xml-stylesheet   type= "text/xsl "   href= "testxsl.xsl " ?> <document>     <resume>             <Name>网</Name>     </resume>     <resume>             <Name>三</Name>     </resume>     <resume>             <Name>七</Name>     </resume>     <resume>             <Name>啊</Name>     </resume> </document> 




testxsl.xsl
XML code
<xsl:stylesheet   version= "1.0 "   xmlns:xsl= "http://www.w3.org/1999/XSL/Transform ">  <xsl:output   method= "html "   indent= "yes "   />  <xsl:template   match= "/ ">    <html>      <body>        <xsl:apply-templates   />      </body>    </html>  </xsl:template>  <xsl:template   match= "document ">    <xsl:variable   name= "cols "   select= "3 "     />    <table   border= "1 ">      <xsl:for-each   select= "resume[(position()   -   1)   mod   $cols   =   0] ">        <tr>          <td>            <xsl:value-of   select= "Name "   />          </td>          <xsl:for-each   select= "following-sibling::resume[position()   &lt;   $cols   ] ">            <td>              <xsl:value-of   select= "Name "   />            </td>          </xsl:for-each>          <!--ignore   the   following   if   you   don 't   understand   it   begin   -->          <xsl:variable   name= "sibcount "   select= "count(following-sibling::resume) "     />          <xsl:if   test= "$sibcount   &lt;   $cols   -   1 ">            <xsl:for-each   select= "(document( ' ')//namespace::*)[position()   &lt;   $cols   -   $sibcount   ] ">              <td> &#160; </td>            </xsl:for-each>          </xsl:if>          <!--end   -->        </tr>      </xsl:for-each>    </table>  </xsl:template></xsl:stylesheet>
  相关解决方案