never-online 's Tech Blog In CSDN

never online - Everlasting love for angela.

用户操作
[即时聊天] [发私信] [加为好友]
never-onlineID:BlueDestiny
153978次访问,排名502好友17人,关注者33
在京城
BlueDestiny的文章
原创 114 篇
翻译 0 篇
转载 8 篇
评论 224 篇
never-online的公告
Web:
www.never-online.net
Email:
BlueDestiny##126.com
QQ:
77091373
最近评论
kwlong2008:来看看朋友,最近过的怎么样?俺的空间是介绍网站制作网站建设的,有时间也常去一下我的空间谢谢,wow gold

When you play a game of the day, the list of friends in the game whether there are always a few names of black
wow power leveling<……
zyhomepage:支持一下
clicksun:如果要制作纯CSS+DIV的圆角方框图形,可以到这里直接在线制作,什么颜色都可以:http://corner.cha.la
C_SuperMe:可以好好学习一下啊!!
文章分类
收藏
相册
icon
JS & DHTML
Dhteumeuleu
Douglas Crockford
Webfx
常去之地
ASP.Net
MSDN英文
XML指南
XML的大本营
博客园
正则表达式
我的网站
我网站的Blog(RSS)
友情链接
KimSoft的blog(RSS)
存档
软件项目交易
订阅我的博客
XML聚合  FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
订阅到BlogLines
订阅到Yahoo
订阅到GouGou
订阅到飞鸽
订阅到Rojo
订阅到newsgator
订阅到netvibes

原创 关于asp模板类收藏

新一篇: 超长文章自动分页(客户端版) | 旧一篇: 关于正则的[]限定符的区间

以前写的一个template class的一个方法,现在看到论坛上有人问我就写了一个示例方法出来,就是一个函数,我不太喜欢写注释,代码的易读性应该不会太差的,如果有什么不懂的,请mail我,我的mail:Bluedestiny [at] 1 6 3 .com

简单介绍一下用法吧:

templateStream是模板数据的变体,为字符串型,当然可以是任何字符型的,读出xml,或是用fso读文件都可以,模板中以<template:rs>数据库中字段</template:rs>表示模板数据,当然我就不把自定义替换等等东西写出来了,这个应该不是很难的,这里只是给个示例以及一个思路。

这个我就不写注释了。其实就是一个替换字符串的一个过程,如果有不懂的,留言给我

<!--#include file="inc/connection.asp"-->
<%
'script Written By Bluedestiny
'option explicit

dim templateStream
dim rsObj,sql

templateStream=""
templateStream=templateStream+"id=<template:rs>hotel_id</template:rs>" & vbnewline
templateStream=templateStream+"<h1 align='center'>酒店名称:<template:rs>hotel_name</template:rs></h1>" & vbnewline
templateStream=templateStream+"<h5>浏览量:<template:rs>hotel_clicked</template:rs>" & vbnewline
templateStream=templateStream+"星级:<template:rs>hotel_level</template:rs>" & vbnewline
templateStream=templateStream+"</h5>"


function loadtemplate(stream,rst)
dim T_Stream
dim startemplate,endtemplate
dim T_RS_S, T_RS_E, T_RS_A, T_RS_V
dim replacedStream
dim startloop, maxloop

T_RS_S="<template:rs>"
T_RS_E="</template:rs>"
replacedStream=""

if isObject(rst) then
Set rs=rst.clone
else
response.Write "recordset not initialize."
exit function
end if

for i=1 to rs.recordcount

T_Stream=stream
startemplate=1
maxloop=1000
startloop=1
startemplate=1

do
if startloop>=maxloop then
response.Write "overflow"
exit do
end if

startemplate=instr(startemplate,stream,T_RS_S,0)
if startemplate=0 then exit do
endtemplate=instr(startemplate,stream,T_RS_E,0)
if endtemplate=0 then exit do

startemplate=startemplate+len(T_RS_S)
T_RS_V=mid(stream,startemplate,endtemplate-startemplate)
T_RS_A=T_RS_S & T_RS_V & T_RS_E
T_Stream=replace(T_Stream,T_RS_A,rs(T_RS_V),1,1,1)

startloop=startloop+1
loop
replacedStream=replacedStream & T_Stream
rs.movenext
next

response.Write replacedStream

end function

function convertTemplateTag(byVal stream)
dim tmp
tmp=stream
tmp=replace(tmp,"<","&lt;")
tmp=replace(tmp,">","&gt;")
convertTemplateTag=tmp
end function

response.Write "<pre>"+convertTemplateTag(templateStream)+"</pre>" & vbnewline

Set rsObj=Server.CreateObject("ADODB.recordset")
sql="SELECT TOP 3 * FROM [NVR_hotel] ORDER BY hotel_id ASC"
rsObj.open sql,conn,1,1
call loadtemplate(templateStream, rsObj)
%>

发表于 @ 2006年01月29日 23:37:00|评论(loading...)|编辑

新一篇: 超长文章自动分页(客户端版) | 旧一篇: 关于正则的[]限定符的区间

评论:没有评论。

发表评论  


当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
Csdn Blog version 3.1a
Copyright © never-online