欢乐园神将三国,娄底论坛,选购水龙头
三、格式转换xsl文件说明(persons.xsl)
??例程中使用xsl对xml(标准化越来越近了)数据进行格式化,并以html的形式返回到客户端。这个过程也可以放在客户端进行,但考虑到兼容性的问题,例程中采用了在服务器端通过asp操纵dom进行格式化的方法。
??xsl文件的内容如下,
<?xml(标准化越来越近了) version="1.0" encoding="gb2312"?> <xsl:stylesheet xml(标准化越来越近了)ns:xsl="https://www.w3.org/1999/xsl/transform" version="1.0"> <xsl:template match="/persons"> <script language="javascript"> function add() { window.open("add.", "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"> <tr> <td align="right"><a href="javascript:add();" title="添加新联系人">添加新联系人</a> </td> </tr> </table>
<table align="center" width="680" cellspacing="1" cellpadding="2" border="0" bgcolor="#666600"> <tr class="title" bgcolor="#e5e5e5"> <td width="25"><xsl:text disable-output-escaping="yes">&</xsl:text>nbsp;</td> <td>姓名</td> <td>英文名</td> <td>手机</td> <td>电话</td> <td>email</td> <td>qq</td> <td>所在公司</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">修改信息 </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> |
??在服务器端的转换使用一个函数来完成,格式化成功,返回html字符串,格式化失败,打印出错误信息,如下,
******************************************* 说明:使用xsl文件格式化xml(标准化越来越近了)文件。 作者:gwd 2002-11-05 参数:strxml(标准化越来越近了)file -- xml(标准化越来越近了)文件,路径+文件名 strxslfile -- xsl文件,路径+文件名 返回:成功 -- 格式化后的html字符串 失败 -- 自定义的错误信息 ******************************************* function formatxml(标准化越来越近了)(strxml(标准化越来越近了)file, strxslfile) dim objxml(标准化越来越近了), objxsl strxml(标准化越来越近了)file = server.mappath(strxml(标准化越来越近了)file) strxslfile = server.mappath(strxslfile) set objxml(标准化越来越近了) = server.createobject("msxml(标准化越来越近了)2.domdocument") set objxsl = server.createobject("msxml(标准化越来越近了)2.domdocument") objxml(标准化越来越近了).async = false if objxml(标准化越来越近了).load(strxml(标准化越来越近了)file) 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 |
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
网友评论