现在是程序处理:
<%
'根据输入判断输出是名称还是数据
Function geturlxml(outfile,mode)
geturlxml=False
If outfile="" Then Exit Function
Dim tab
Select Case killint(mode,0,0,2)
Case 0:tab="szd_tpl"
Case 1:tab="szd_content"
End Select
Set rs=conn.execute("select ["&tab&"] FROM szd_asp where [szd_link]='"&outfile&"'")
If rs.eof And rs.bof Then
Exit Function
else
geturlxml=rs(tab)
End If
End Function
'提取include文件到原始的数据项中
Function getincludefile(x)
Dim regxml,html
html=""
Set regxml=new regexp
regxml.ignorecase=True
regxml.global=True
regxml.pattern="(<!--#include)(\s)(file|virtual)(=)(\u0022)([a-zA-Z][A-Za-z0-9_/]{0,30})(.)(asp|inc|dll)(\u0022)(-->)"
Dim Matches,Match
Set Matches = regxml.Execute(x)
For Each Match in Matches
html=html&match.value
Next
getincludefile=html
End Function
'获取模板项,先判断输出,返回值是 html 形式的模板,参数是模板的名称
Function gettpl(url)
Dim mudule_file,xml_file,asp_file
xml_file=url
asp_file=gettpldata(xml_file,0)'由模板名称获取模板的内容
Dim loadxml,parsexml,nodes,node
Set loadxml = Server.CreateObject("MSxml2.DOMDocument")
loadxml.async=false
parsexml=server.mappath("../"&gettpldata(xml_file,10)&xml_file)'装载本地的xml文档,先到数据库取到路径
loadxml.load parsexml
Set nodes = loadxml.selectNodes("//*")
for each node in nodes
asp_file=insertaspinhtml(asp_file,gettpldata(node.nodename,1),node.nodename)'加载模块到模板,输出html模板
Next
gettpl=asp_file
End function
'匹配模板中的数据项
'把data中的数据传入html文件当中去
Function tpltodata(html,data)
Dim regxml
Set regxml=new regexp
regxml.ignorecase=True
regxml.global=True
regxml.pattern="({%)([a-zA-Z][A-Za-z0-9_]{2,60})(%})(.[^\[]*)({%/)\2(%})"
Dim Matches,Match
Set Matches = regxml.Execute(data)
For Each Match in Matches
html=Replace(html,"{%"®xml.Replace(match.value,"$2")&"%}",regxml.Replace(match.value,"$4"))
Next
tpltodata=html
End Function
'geturlxml 传入参数模板名称,返回模板的内容,失败的时候返回 null
Function geturlxml(outfile)
geturlxml=Null
If outfile="" Then Exit Function
Set rs=conn.execute("select [szd_tpl] FROM szd_asp where [szd_link]='"&outfile&"'")
If rs.eof And rs.bof Then
Exit Function
else
geturlxml=rs("szd_tpl")
End If
End Function
public Function gettpldata(url,mode)
'Set rs=server.CreateObject("server.adodbrecordset")
If Len(url)<1 Then Exit Function
Dim szd_keytpl
Select Case mode
Case 0:Set rs=conn.execute("select [szd_content] from szd_tpl where [szd_link]='"&url&"'")
Case 10:Set rs=conn.execute("select [szd_url] from szd_tpl where [szd_link]='"&url&"'")
Case 1:Set rs=conn.execute("select [szd_content] from szd_keytpl where [szd_key]='"&url&"'")
End Select
If Not(rs.eof And rs.bof) Then
szd_keytpl=rs(0)
Else
szd_keytpl="<div>{%nodefined%}</div>"
End If
gettpldata=szd_keytpl
End Function
'加载标记的模块到 xml 格式的模板中,输出html格式的模板,asp:xml格式模板,html:导入的模块,xmls:当前标记
Function insertaspinhtml(asp,html,xmls)
Dim regxml,temp,temps,tempasp,tempasp_e
Set regxml=new regexp
regxml.ignorecase=True
regxml.global=True
regxml.pattern="(\<"&xmls&"\>)(.[^\[]*)(\<\/"&xmls&"\>)"
temp=regxml.Replace(asp,"$2")
Dim Matches,Match
Set Matches = regxml.Execute(asp)
For Each Match in Matches
html=Replace(html,"(&"&xmls&"&)",regxml.Replace(match.value,"$2"))
asp=Replace(asp,Match.Value,html)
next
temps=Replace(html,"(&"&xmls&"&)",temp)
insertaspinhtml=asp
End Function
Function update_aspfile(id)
Dim update_aspfile_return
update_aspfile_return=False
id=killint(id,0,0,14)
If id=0 Then Exit Function
Set rs=conn.execute("select [szd_level],[szd_content],[szd_tpl],[szd_link] from szd_asp where id="&id&"")
If rs.eof And rs.bof Then Exit Function
Dim tpl_level,tpl_content,tpl_tpl,html_content,asp_file_now
tpl_level=rs(0)
tpl_content=rs(1)
tpl_tpl=rs(2)
asp_file_now=rs(3)
If Len(tpl_tpl)<4 Or tpl_level=1 Or IsNull(tpl_tpl) Then
html_content=tpl_content
Else
html_content=gettpl(tpl_tpl)
If Not isnull(html_content) Then
html_content=getincludefile(tpl_content)&tpltodata(html_content,tpl_content)
'response.write("<hr/>"&server.htmlencode(getincludefile(tpl_content))&"<hr/>")
Else
html_content=tpl_content
'response.write("<hr/>"&server.htmlencode(html_content)&"<hr/>")
End If
End If
If writeto("../",asp_file_now,html_content,2) Then update_aspfile_return=True
update_aspfile=update_aspfile_return
End Function
%>
