3。フォーマット変換XSLファイル(Persons.xsl)の説明
ルーチンでは、XSLを使用してXMLデータをフォーマットし、HTMLのクライアントに戻します。このプロセスはクライアント側でも実行できますが、互換性の問題を考慮すると、ルーチンはサーバー側のASPを介してフォーマットする方法を採用しています。
XSLファイルの内容は次のとおりです。
<?xmlバージョン= "1.0" encoding = "gb2312"?> xsl:styleSheet xmlns:xsl = "http://www.w3.org/1999/xsl/transform"バージョン= "1.0"> <XSL:Template Match = "/persons"> <スクリプト言語= "javascript"> 関数add() { window.open( "add.asp"、 "add"、 "width = 300、height = 320、resize = no"); } 関数編集(intid) { window.open( "edit.asp?id ="+intid、 "edit"、 "width = 300、height = 320、resize = no"); } </スクリプト> <テーブルalign = "center"> <tr> <td align = "right"> <a href = "javascript:add();">新しい連絡先を追加</a> </td> </tr> </表> <テーブルalign = "center" cellpacing = "1" cellpadding = "2" bgcolor = "#666600"> <tr bgcolor = "#e5e5e5"> <TD >< XSL:テキスト無効-OUTPUT-ESCAPING = "YES" <td>名</td> <td>英語名</td> <TD>携帯電話/TD> <td> tel </td> <td>メール</td> <td <TD 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:属性名= "href"> javascript:edit( '<xsl:value-of select = "position()"/>'); </xsl :属性> <xsl:属性name = "title">修正情報</xsl:属性> <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:属性name = "href"> mailto:<xsl:value-of select = "email"/></xsl:属性> <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> </表> </XSL:テンプレート> </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) objxml = server.createobject( "msxml2.domdocument")を設定します objxsl = server.createobject( "msxml2.domdocument")を設定します objxml.async = false objxml.load(strxmlfile)の場合 objxsl.async = false objxsl.validateonparse = false objxsl.load(strxslfile)の場合 エラーの再開時に次の '変換ノードメソッドのキャッチエラー formatxml = objxml.transformnode(objxsl) objxsl.parseerror.errorcode <> 0の場合 Response.Write " Response.write "エラーコード:"&objxsl.parseerror.errorcode response.write "<br>エラー理由:"&objxsl.parseerror.reason Response.write "<br>エラーライン:"&objxsl.parseerror.line formatxml = "<spanalert" "> format xmlファイルエラー!</span>" ifを終了します それ以外 Response.Write " Response.write "エラーコード:"&objxsl.parseerror.errorcode response.write "<br>エラー理由:"&objxsl.parseerror.reason Response.write "<br>エラーライン:"&objxsl.parseerror.line formatxml = "<spanAlert" ">エラーxslファイル!</span>" ifを終了します それ以外 Response.Write " Response.write "エラーコード:"&objxml.parseerror.errorcode Response.write "<br>エラー理由:"&objxml.parseerror.reason response.write "<br>エラーライン:"&objxml.parseerror.line formatxml = "<spanAlert" ">エラーxmlファイル!</span>" ifを終了します objxsl = Nothingを設定します objxml =何も設定しません エンド関数 |