Instance Walkthrough Asp+xml Programming (2)

Source: Internet
Author: User
Tags error code html form xsl xsl file
Iii. format Conversion XSL file description (persons.xsl)

The XML data is formatted using XSL in the process and returned to the client in HTML form. This process can also be done on the client side, but given the compatibility problem, the routine uses the ASP to manipulate the DOM on the server side to format the method.

The contents of the xsl file are as follows,

function edit (INTID)
{
window.open ("edit.asp?id=" +intid, "edit", "Width=300,height=320,resize=no");
}
</script>
<table width= "border=" "0" align= "center"
<tr>
<TD align= "Right" ><a href= Javascript:add (); "title= Add New Contact" > add new contact </a> </td>
</tr>
</table>

<table align= "center" width= "680" cellspacing= "1" cellpadding= "2" border= "0" bgcolor= "#666600"
<TR class= "title" Bgcolor= "#E5E5E5"
<TD width= "><xsl:text" disable-output-escaping= "yes" >& </xsl:text> nbsp; </td>
<td> name </td>
<td> English name </td>
<td> Mobile </td>
<td> Phone </td>
<td> Email </td>
<td> QQ </td>
<td> your company </td>
</tr>
<xsl:for-each select= "Person" >
<TR bgcolor= "#FFFFFF" >
<TD align= "right" ><xsl:value-of select= "position ()"/> </TD>
<TD style= "COLOR: #990000" > <A> <xsl:attribute name= "HREF" >javascript:edit (' <xsl:value-of select= "position ()"/> "); </ Xsl:attribute><xsl:attribute name= "title" Modify information </xsl:attribute> <xsl:value-of select= "name"/> </A> </TD>
<TD> <xsl:value-of select= "Nick"/> </TD>
<TD> <xsl:value-of select= "Mobile"/> </TD>
<TD> <xsl:value-of select= "Tel"/> </TD>
<TD> <A> <xsl:attribute name= "HREF" >mailto:<xsl:value-of select= "Email"/> </xsl:attribute> <xsl:value-of select= " Email "/> </A> </TD>
<TD> <xsl:value-of select= "QQ"/> </TD>
<TD> <xsl:value-of select= "Company"/> </TD>
</TR>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>

The conversion on the server side uses a function to complete, format successfully, return the HTML string, format failed, print out the error message, such as the following,

'*******************************************
' Description: Format the XML file with the XSL file.
' Author: gwd 2002-11-05
' Parameters: Strxmlfile--XML file, path + filename
' Strxslfile--xsl file, path + filename
' Return: Success--formatted HTML string
' Failure--Custom error message
'*******************************************
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 ' captures Transformnode method errors
Formatxml = Objxml.transformnode (objxsl)
If objXsl.parseError.errorCode <> 0 Then
Response.Write "<br> 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" "> format XML file Error!" </span> the
End If
Else
Response.Write "<br> 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" "> loading XSL file error!" </span> the
End If
Else
Response.Write "<br> 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" "> loading XML file Error!" </span> the
End If

Set objxsl = Nothing
Set Objxml = Nothing
End Function



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.