3. 형식 변환 설명 XSL 파일 (persons.xsl)
일상에서 XSL은 XML 데이터를 포맷하고 HTML의 클라이언트로 반환하는 데 사용됩니다. 이 프로세스는 클라이언트 측에서도 수행 될 수 있지만 호환성 문제를 고려할 때 일상은 서버 측에서 ASP를 통해 서식하는 방법을 채택합니다.
XSL 파일의 내용은 다음과 같습니다.
<? xml 버전 = "1.0"encoding = "gb2312"? xsl : 스타일 시트 xmlns : xsl = "http://www.w3.org/1999/xsl/transform"version = "1.0"> xsl : 템플릿 매치 = "/persons"> script 언어 = "JavaScript"> 함수 add () { window.open ( "add.asp", "add", "width = 300, 높이 = 320, resize = no"); } 기능 편집 (intid) { window.open ( "edit.asp? id ="+intid, "edit", "width = 300, 높이 = 320, resize = no"); } </스크립트 ipt table table align = "Center"> < tr > < td align = "right"> < a href = "javaScript : add ();"> 새 연락처 추가 </a> </td> </tr > </테이블 > < 테이블 align = "Center"CellPacing = "1"CellPadding = "2"bgcolor = "#666600"> tr tr bgcolor = "#e5e5e5"> < TD >< XSL : 텍스트 비활성화 출력-스케이프 = "yes"> & </xsl : 텍스트 > nbsp; </td > < td > 이름 </td > < TD > 영어 이름 </td > TD > 휴대 전화 </td > < td > tel </td > < TD > 이메일 </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 : 속성 이름 = "title"> 수정 정보 </xsl : attribute> < xsl : value-of select = "name"/> </> </a> </td > < td >< xsl : select value-of select = "nick"/></td > < TD >< xsl : select value-of select = "mobile"/></td > < td >< xsl : select value-of select = "tel"/></td > < td ><ad xsl : 속성 이름 = "href"> mailto : < xsl : value-of select = "이메일"/></xsl : attribute> < xsl : value-of select = "email"/> </a t/td > < td >< xsl : select value-of select = "qq"/></td > < TD >< XSL : 값 선택 = "회사"/></td > </tr > </xsl : for-each > </테이블 > </xsl : 템플릿 > </xsl : 스타일 시트 > |
서버 측의 변환은 함수를 사용하여 완료되고 HTML 문자열이 반환되고 서식이 실패하고 오류 메시지가 다음과 같이 인쇄됩니다.
'******************************************************** '설명 : XSL 파일을 사용하여 XML 파일을 형식화하십시오. '저자 : GWD 2002-11-05 '매개 변수 : stxmlfile -xml 파일, 경로 + 파일 이름 'stxslfile -xsl 파일, Path + 파일 이름 '반환 : 성공 - 포맷 된 HTML 문자열 '실패 - 사용자 정의 오류 메시지 '******************************************************** fortmatxml (stxmlfile, stxslfile) dim objxml, objxsl stxmlfile = server.mappath (stxmlfile) stxslfile = server.mappath (stxslfile) set objxml = server.createobject ( "msxml2.dodocument") set objxsl = server.createobject ( "msxml2.dodocument") objxml.async = false objxml.load (strxmlfile) 인 경우 objxsl.async = false objxsl.validateonparse = false objxsl.load (stxslfile) 인 경우 오류가 다시 시작됩니다. 다음 'TransformNode 메서드의 캐치 오류 formatxml = objxml.transformnode (objxsl) if objxsl.parseerror.errorcode <> 0 인 경우 response.write ""BR> < hr>" 응답. "오류 코드 :"& objxsl.parseerror.errorcode response.write ""BR> 오류 이유 :"& objxsl.parseerror.Reason response.write ""BR> 오류 줄 :"& objxsl.perseerror.line formatxml = "< spanalert" "> format xml 파일 오류! </span>" 끝 If 또 다른 response.write ""BR> < hr>" 응답. "오류 코드 :"& objxsl.parseerror.errorcode response.write ""BR> 오류 이유 :"& objxsl.parseerror.Reason response.write ""BR> 오류 줄 :"& objxsl.perseerror.line formatxml = "< spanalert" "> 오류로드 XSL 파일! </span>" 끝 If 또 다른 response.write ""BR> < hr>" 응답. "오류 코드 :"& objxml.parseerror.errorcode response.write ""BR> 오류 이유 :"& objxml.parseerror.Reason response.write ""br> 오류 줄 :"& objxml.parseerror.line formatxml = "< spanalert" "> 오류로드 XML 파일! </span>" 끝 If OBJXSL = 아무것도 설정하지 않습니다 OBJXML = 아무것도 설정하지 않습니다 엔드 기능 |