Tema: Menu xml
Ver Mensaje Individual
  #4 (permalink)  
Antiguo 16/08/2006, 15:37
micayael
 
Fecha de Ingreso: noviembre-2003
Ubicación: Paraguay
Mensajes: 382
Antigüedad: 21 años, 5 meses
Puntos: 4
Posteo el código para los que no consiguen bajarlo

<%
' DATE: 8/00
' AUTHOR: Chris Faranetta
' DESC: This will do an XML\XSL transformation against two XML Document files. The sources passed in can
' be either an XML Document string, an MSXML(2).DOMDocument or node, or a filename.
' I'm assuming that if a filename is passed in, it will have a three letter extension.
' NOTE: The XSLSrc could be a cached XSL Template from an ASP Application Session.
' NOTE: All documents are loaded as Free Threaded - this does effect performance if you are not caching your style sheets.
' PARAMS: vXMLSrc - either the XML Document filename or a text string containing the XML Document or an Object.
' vXSLSrc - either the XSL Document filename or a text string containing the XSL Document or an Object.
' vParamList - an array of name\value pairs to be passed into the XSL Template.
' EX: array( array( param_name1, param_val1 ), array( param_name2, param_val2 ), ... )
' RETURNS: some kind of text (HTML, WML, HDML, XHTML, ... )!!!
function tformEx( vXMLSrc, vXSLSrc, vParamList )
dim oXML
dim oXSL

' Load the documents we need for a transformation.
set oXML = LoadDocument( vXMLSrc ) ' load the XML Document
if ( oXML.parseError <> 0 ) then
tformEx = "tFormEx(): Load of the XML Document failed in tformEx(), reason: " & oXML.parseError.reason & "<br></br>"
set oXML = nothing
exit function
end if

set oXSL = LoadDocument( vXSLSrc ) ' load the XSLT Document.
if ( oXSL.parseError <> 0 ) then
tformEx = "tFormEx(): Load of the XSL Document failed in tformEx(), reason: " & oXSL.parseError.reason & " " & oXSL.parseError.line & "<br></br>"
set oXML = nothing
set oXSL = nothing
exit function
end if

' prep for the transformation.
dim oProc
dim oParam
dim oTemplate

set oTemplate = server.createobject( "MSXML2.XSLTemplate")
oTemplate.stylesheet = oXSL
set oProc = oTemplate.createProcessor()
oProc.input = oXML

' do params
on error resume next

if ( not isNull(vParamList) ) then
for each oParam in vParamList
oProc.addParameter oParam(0), oParam(1) ' name, value
next
end if

if ( err.number <> 0 ) then
tformEx = "tformEx(): Invalid parameter; " & err.description & ", " & err.number
set oXML = nothing
set oXSL = nothing
set oProc = nothing
exit function
end if

' do the transformation
oProc.transform
tformEx = oProc.output

set oXML = nothing
set oXSL = nothing
set oProc = nothing
end function


' DATE: 8/00
' AUTHOR: Chris Faranetta
' DESC: This will do an XML\XSL transformation against two XML Document files. The sources passed in can
' be either an XML Document string, an MSXML(2).DOMDocument or node, or a filename.
' I'm assuming that if a filename is passed in, it will have a three letter extension.
' NOTE: The XSLSrc could be a cached XSL Template from an ASP Application Session.
' PARAMS: vXMLSrc - either the XML Document filename or a text string containing the XML Document or an Object.
' vXSLSrc - either the XSL Document filename or a text string containing the XSL Document or an Object.
' RETURNS: some kind of text (HTML, WML, HDML, XHTML, ... )!!!
function tform( vXMLSrc, vXSLSrc )
tform = tformEx( vXMLSrc, vXSLSrc, null )
end function


' DATE: 8/00
' AUTHOR: Chris Faranetta
' DESC: Does an intelligent load of an XML Document.
' PARAMS: vXMLSrc - A file name, XML Document text string or an XML DOM object.
' RETURNS: an XML DOM Object
function LoadDocument( vXMLSrc )
dim oXML

if ( typename( vXMLSrc ) = "Object" Or typename( vXMLSrc ) = "DOMDocument") then
set oXML = vXMLSrc ' This is easy, already an object!
else ' either load a filename or an XML Document string.
set oXML = server.CreateObject( "MSXML2.FreeThreadedDOMDocument" )
oXML.async = false

' clean this up in case it is a filename.
vXMLSrc = rtrim( cstr(vXMLSrc) )

' If we assume there is an extension of .xyz at the end (where xyz is some 3 letter extension), then it must be a filename.
if ( mid( vXMLSrc, len( vXMLSrc ) - 3, 1 ) = "." ) then ' this is a filename
oXML.load server.mappath( vXMLSrc )
else
oXML.loadXML vXMLSrc ' this is a text string
end if
end if

set LoadDocument = oXML
end function
%>