3. Descrição do arquivo XSL de conversão de formato (PESSONS.XSL)
Na rotina, o XSL é usado para formatar os dados XML e retornar ao cliente em HTML. Esse processo também pode ser realizado no lado do cliente, mas, considerando o problema de compatibilidade, a rotina adota o método de formatação através do ASP no lado do servidor.
O conteúdo do arquivo XSL é o seguinte:
<? XML versão = "1.0" Encoding = "GB2312"? > < XSL: Stylesheet xmlns: xsl = "http://www.w3.org/1999/xsl/transform" version = "1.0"> < XSL: modelo correspondente = "/pessoas"> < Script Language = "JavaScript"> função add () { window.open ("add.asp", "add", "width = 300, altura = 320, redimensionar = não"); } Editar função (INTID) { window.open ("edit.asp? id ="+intid "," editar "," largura = 300, altura = 320, redimensionar = não "); } </script > < tabela align = "Center" > < TR > < td align = "direita"> < a href = "javascript: add ();"> adicione um novo contato </a> </td> </tr > </Tabela > < Tabela align = "Center" CellPacing = "1" CellPadding = "2" BGCOLOR = "#666600"> < tr bgcolor = "#e5e5e5" > < TD >< XSL: Texto desabille-output-escaping = "Sim" > & </xsl: texto > nbsp; </td > < td > nome </td > < td > Nome em inglês </td > < TD > Telefone celular </TD > < TD > Tel </Td > < TD > Email </TD > < Td > qq </td > < TD > Empresa onde você está localizado </td > </tr > < XSL: para-EAGE SELECT = "Pessoa" > < tr bgcolor = "#ffffff" > < td align = "direita"> < xsl: value-of Select = "position ()"/> </td> < td style = "cor:#990000"> <a> < xsl: atributo name = "href"> javascript: edit ('< xsl: value-of select = "position ()"/>'); </xsl : atributo> < xsl: atributo name = "title"> informações de modificação </xsl: atributo> < xsl: value-of select = "name"/> </a> </td > < TD >< XSL: Valor-of Select = "Nick"/></Td > < TD >< XSL: Valor-of Select = "Mobile"/></TD > < TD >< XSL: Valor-of Select = "Tel"/></Td > < TD ><A>< XSL: Nome do atributo = "href" > Mailto: < xsl: value-of Select = "email"/></xsl: atributo> < xsl: value-of Select = "email"/> </a></td > < TD >< XSL: Valor-of Select = "QQ"/></TD > < TD >< XSL: Value-of Select = "Company"/></Td > </tr > </xsl: for-Eacha > </Tabela > </xsl: modelo > </xsl: folha de estilo > |
A conversão no lado do servidor é concluída usando uma função.
'************************************************** 'Descrição: Formate o arquivo XML usando um arquivo XSL. 'Autor: GWD 2002-11-05 'Parâmetros: strxmlfile - arquivo xml, caminho + nome do arquivo 'strxslfile - arquivo xsl, caminho + nome do arquivo 'Retorno: Sucesso - String HTML formatada 'Falha - mensagem de erro personalizada '************************************************** Função 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 Se objxml.load (strxmlfile) então objxsl.async = false objxsl.validateOnParse = false Se objxsl.load (strxslfile) então No erro, retomar os erros de captura no método de transformNode Formatxml = objxml.transformNode (objxsl) Se objxsl.parseerror.errorcode <> 0 então Response.Write "<br> < hr>" Response.Write "Código de erro:" & objxsl.parseerror.errorcode Response.Write "<br> Razão de erro:" & objxsl.parseerror.Reason Response.write "<br> linha de erro:" & objxsl.parseerror.line Formatxml = "< Spanalert" "> Formato XML ERRO! </span>" Final se Outro Response.Write "<br> < hr>" Response.Write "Código de erro:" & objxsl.parseerror.errorcode Response.Write "<br> Razão de erro:" & objxsl.parseerror.Reason Response.write "<br> linha de erro:" & objxsl.parseerror.line Formatxml = "< Spanalert" "> Erro carregando arquivo xsl! </span>" Final se Outro Response.Write "<br> < hr>" Response.Write "Código de erro:" & objxml.parseerror.errorcode Response.Write "<br> Razão de erro:" & objxml.parseerror.Reason Response.write "<br> linha de erro:" & objxml.parseerror.line Formatxml = "< Spanalert" "> Erro carregando arquivo xml! </span>" Final se Definir objxsl = nada Defina objxml = nada Função final |