<form id="hz9zz"></form>
  • <form id="hz9zz"></form>

      <nobr id="hz9zz"></nobr>

      <form id="hz9zz"></form>

    1. 明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

      案例演練ASP+XML編程(2)

      [摘要]三、格式轉換XSL文件說明(Persons.xsl)例程中使用XSL對XMl數據進行格式化,并以HTML的形式返回到客戶端。這個過程也可以放在客戶端進行,但考慮到兼容性的問題,例程中采用了在服務...
        三、格式轉換XSL文件說明(Persons.xsl)

      例程中使用XSL對XMl數據進行格式化,并以HTML的形式返回到客戶端。這個過程也可以放在客戶端進行,但考慮到兼容性的問題,例程中采用了在服務器端通過ASP操縱DOM進行格式化的方法。

      XSL文件的內容如下,

      <?xml version="1.0" encoding="gb2312"?>
      <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <xsl:template match="/Persons">
      <script language="javascript">
       function add()
       {
        window.open("add.asp", "add", "width=300,height=320,resize=no");
       }

       function edit(intId)
       {
        window.open("edit.asp?id="+intId, "edit", "width=300,height=320,resize=no");
       }
      </script>
      <table width="600" border="0" align="center">
      。紅r>
       。紅d align="right"><a href="javascript:add();" title="添加新聯系人">添加新聯系人</a>  </td>
      。/tr>
      </table>

      <table align="center" width="680" cellspacing="1" cellpadding="2" border="0" bgcolor="#666600">
      。紅r class="title" bgcolor="#E5E5E5">
       。紅d width="25"><xsl:text disable-output-escaping="yes">&</xsl:text>nbsp;</td>
       。紅d>姓名</td>
       。紅d>英文名</td>
       。紅d>手機</td>
       。紅d>電話</td>
       。紅d>Email</td>
       。紅d>QQ</td>
       。紅d>所在公司</td>
      。/tr>
      。紉sl:for-each select="Person">
      。糡R BGCOLOR="#FFFFFF">
       。糡D ALIGN="right"><xsl:value-of select="position()"/></TD>
       。糡D STYLE="color:#990000"><A><xsl:attribute name="HREF">javascript:edit('<xsl:value-of select="position()"/>');</xsl:attribute><xsl:attribute name="title">修改信息 。/xsl:attribute><xsl:value-of select="Name"/></A></TD>
       。糡D><xsl:value-of select="Nick"/></TD>
       。糡D><xsl:value-of select="Mobile"/></TD>
       。糡D><xsl:value-of select="Tel"/></TD>
       。糡D><A><xsl:attribute name="HREF">mailto:<xsl:value-of select="Email"/></xsl:attribute><xsl:value-of select="Email"/></A></TD>
       。糡D><xsl:value-of select="QQ"/></TD>
       。糡D><xsl:value-of select="Company"/></TD>
      。/TR>
      。/xsl:for-each>
      </table>
      </xsl:template>
      </xsl:stylesheet>

      在服務器端的轉換使用一個函數來完成,格式化成功,返回HTML字符串,格式化失敗,打印出錯誤信息,如下,

      '*******************************************
      ' 說明:使用XSL文件格式化XML文件。
      ' 作者:gwd 2002-11-05
      ' 參數:strXmlFile -- Xml文件,路徑+文件名
      ' strXslFile -- Xsl文件,路徑+文件名
      ' 返回:成功 -- 格式化后的HTML字符串
      ' 失敗 -- 自定義的錯誤信息
      '*******************************************
      Function FormatXml(strXmlFile, strXslFile)
       Dim objXml, objXsl

       strXmlFile = Server.MapPath(strXmlFile)
       strXslFile = Server.MapPath(strXslFile)

       Set objXml = Server.CreateObject("MSXML2.DOMDocument")
       Set objXsl = Server.CreateObject("MSXML2.DOMDocument")

       objXML.Async = False
       If objXml.Load(strXmlFile) Then
        objXsl.Async = False
        objXsl.ValidateonParse = False
        If objXsl.Load(strXslFile) Then
         On Error Resume Next ' 捕獲transformNode方法的錯誤
         FormatXml = objXml.transformNode(objXsl)
         If objXsl.parseError.errorCode <> 0 Then
          Response.Write "<br><hr>"
          Response.Write "Error Code: " & objXsl.parseError.errorCode
          Response.Write "<br>Error Reason: " & objXsl.parseError.reason
          Response.Write "<br>Error Line: " & objXsl.parseError.line
          FormatXml = "<span class=""alert"">格式化XML文件錯誤。/span>"
         End If
        Else
         Response.Write "<br><hr>"
         Response.Write "Error Code: " & objXsl.parseError.errorCode
         Response.Write "<br>Error Reason: " & objXsl.parseError.reason
         Response.Write "<br>Error Line: " & objXsl.parseError.line
         FormatXml = "<span class=""alert"">裝載XSL文件錯誤。/span>"
        End If
       Else
        Response.Write "<br><hr>"
        Response.Write "Error Code: " & objXml.parseError.errorCode
        Response.Write "<br>Error Reason: " & objXml.parseError.reason
        Response.Write "<br>Error Line: " & objXml.parseError.line
        FormatXml = "<span class=""alert"">裝載XML文件錯誤。/span>"
       End If

       Set objXsl = Nothing
       Set objXml = Nothing
      End Function




      日韩精品一区二区三区高清