<b>浅谈 ASP 模板技术之参数传递</b>(3)
OK好了,那怎么解析像上面<tagloop:>内容呢?
下面就是一个函数:
复制代码 代码如下:
'【功能】解析并替换相应的模板标签内容
function ParseTag(ByVal strTag)
dim arrResult, ClassName, arrAttributes, sTemp, i, objClass
'如果标签是空的则退出函数
if len(strTag) = 0 then exit function
'Split the match on the colon character (:)
arrResult = Split(strTag, ":")
'Split the second item of the resulting array on the space character, to
'retrieve the name of the class
ClassName = Split(arrResult(1), " ")(0)
'Use a select case statement to work out which class we're dealing with
'and therefore which properties to populate etc
select case uCase(ClassName)
'It's a loop class, so instantiate one and get it's properties
case "LOOP"
set objClass = new LOOP_Class
LOOP.Channelid= GetAttribute("channelid", strTag")
LOOP.Pagesize= GetAttribute("pagesize", strTag")
LOOP.title = GetAttribute("title", strTag")
LOOP.type = GetAttribute("Type", strTag")
ParseTag = LOOP.column (GetAttribute("column", strTag"), true)
'Destroy our class object
set objClass = nothing
end select
end function
上面的loop是一个类,这里也不再详说了。因为好久没有说话了,不太习惯,呵呵。
结论,通过上面的函数,你可以很快的编写相关的模板程序了。希望对你有帮助。