ASP处理XSLT转换XML的实现
程序员文章站
2022-08-09 18:15:28
使用asp处理xslt转换xml比较简单,思路如下:创建一个xsltemplate的对象,再创建一个xmldom对象,然后在家xml文件和xslt文件,最后使用方法transform即可,包含到类...
使用asp处理xslt转换xml比较简单,思路如下:创建一个xsltemplate的对象,再创建一个xmldom对象,然后在家xml文件和xslt文件,最后使用方法transform即可,包含到类里面,具体代码如下。
class cls_xml_transform
private linput,xsltemplate
private p_output
public property get output()
output = p_output
end property
private property let output(byval strinfo)
p_output = strinfo
end property
public property let input(byval vnewvalue)
if isobject(vnewvalue) then set linput=vnewvalue
end property
public property let xsltemplatefile(byval vnewvalue)
dim stylesheet
dim vnewvalue_
vnewvalue_ = vnewvalue
if not instr(vnewvalue,":") > 0 then
vnewvalue = server.mappath(vnewvalue)
end if
set xsltemplate=server.createobject("msxml2.xsltemplate")
set stylesheet=server.createobject("microsoft.freethreadedxmldom")
stylesheet.load vnewvalue
xsltemplate.stylesheet=stylesheet
end property
public sub transform()
dim proc
set proc = xsltemplate.createprocessor()
proc.input=linput
proc.transform()
output=proc.output
set proc=nothing
end sub
end class
private linput,xsltemplate
private p_output
public property get output()
output = p_output
end property
private property let output(byval strinfo)
p_output = strinfo
end property
public property let input(byval vnewvalue)
if isobject(vnewvalue) then set linput=vnewvalue
end property
public property let xsltemplatefile(byval vnewvalue)
dim stylesheet
dim vnewvalue_
vnewvalue_ = vnewvalue
if not instr(vnewvalue,":") > 0 then
vnewvalue = server.mappath(vnewvalue)
end if
set xsltemplate=server.createobject("msxml2.xsltemplate")
set stylesheet=server.createobject("microsoft.freethreadedxmldom")
stylesheet.load vnewvalue
xsltemplate.stylesheet=stylesheet
end property
public sub transform()
dim proc
set proc = xsltemplate.createprocessor()
proc.input=linput
proc.transform()
output=proc.output
set proc=nothing
end sub
end class
使用范例:
set xmldom = server.createobject("microsoft.freethreadedxmldom")
xmldom.async = false
xmldom.load(server.mappath("bi2.xml"))
set o=new cls_io_transform
o.xsltemplatefile="bi2.xsl"
o.input=xmldom
o.transform()
response.write o.output()
xmldom.async = false
xmldom.load(server.mappath("bi2.xml"))
set o=new cls_io_transform
o.xsltemplatefile="bi2.xsl"
o.input=xmldom
o.transform()
response.write o.output()
这里处理的直接是xmldom对象了,如果需要,灵活可以修改
下一篇: [C++]资源管理