Using XML to implement BBS (topic list) _xml/rss

Source: Internet
Author: User
Tags xsl xsl file
Table A:
1-0-1,this is a test
3-1-1,this is a test
4-3-1,this is a test
5-3-1,this is a test
2-0-2,this is a test
The above is an example of a list of BBS topics. In general, if you are not using Oracle (Oracle has a query that automatically generates a family tree, consult the Select ... startwith ... connect by ...). Statement, it is a cumbersome task to implement the list of examples (which many programmers have written).
What happens if we use XML instead?
Now we use "Select * from BBS" to query the post from the database and return it in XML format (if you use ADO, you can use it recordset.save ... adpersistxml directly generated, of course, if you don't like the format generated by ADO, Available program generation, as in this case):
Table B:
<?xml version= "1.0"?>
<?xml-stylesheet type= "text/xsl" href= "b.xsl"?>
<bbs>
<post sid= "4" pid= "3" aid= "1" >
<title>4-3-1,this is a test</title>
<content>slddfjslajfsdljf</content>
</post>
<post sid= "5" pid= "3" aid= "1" >
<title>5-3-1,this is a test</title>
<content>slddfjslajfsdljf</content>
</post>
<post sid= "3" pid= "1" aid= "1" >
<title>3-1-1,this is a test</title>
<content>slddfjslajfsdljf</content>
</post>
<post sid= "1" pid= "0" aid= "1" >
<title>1-0-1,this is a test</title>
<content>slddfjslajfsdljf</content>
</post>
<post sid= "2" pid= "0" aid= "2" >
<title>2-0-2,this is a test</title>
<content>slddfjslajfsdljf</content>
</post>
</bbs>
Description: Here SID is the ID number of the post, PID is the parent ID number of the posts. Title is titled, Content is the contents of the post.
The second row in the table above specifies the use of B. XSL to transform the XML content. This is the information provided to IE5. If you use XMLDOM, then you may not want this message.
Let's take a look at how the XML content of the table above is displayed as an XSL file in the form of table A:
Table c:b.xsl
<?xml version= ' 1.0 '?>
<xsl:stylesheet xmlns:xsl= "Http://www.w3.org/TR/WD-xsl" >
<xsl:template match= "/" >
<body>
<xsl:apply-templates select= "*"/>
</body>
</xsl:template>
<xsl:template match= "POST" >
<li>
<div>
<xsl:attribute name= "title" ><xsl:value-of select= "content"/></xsl:attribute>
<xsl:value-of select= "title"/>
<xsl:if test= "/bbs/post[@pid =context ()/@sid]" >
<xsl:element name= "ul" >
<xsl:apply-templates select= "/bbs/post[@pid =context ()/@sid]"/>
</xsl:element>
</xsl:if>
</div>
</li>
</xsl:template>
<xsl:template match= "BBS" >
<ul>
<xsl:apply-templates select= "post[@pid =0]"/>
</ul>
</xsl:template>
</xsl:stylesheet>
Now you save Table B as Abc.xml, save the contents of Table C as b.xsl, and then open it in IE5, and you can see the same things as table A.
As you can see, the XSL file is the final result of the display. If you have more than one forum, you do not need to change the forum program, as long as the various sub forums to provide different XSL files, you can make the version of each sub-forum regardless of style or theme arrangement will have a unique performance. If free forum services are available, it is a good choice to allow forum applicants to customize their own XSL files.
But what if the client doesn't support XML? The answer is simple, the server will first convert XML into HTML, and then upload to the client.
Here we implement this example with Iis4/5+ie5+asp (server must install IE5):
<%@ LANGUAGE = JScript%>
<%
Set rsxml=server.createobject ("ADODB. RecordSet ");
sSQL = "SELECT * FROM BBS"
sconn = "You write Yourself"
Rsxml.cursorlocation = adUseClient
Rsxml.open sSQL, sconn, adOpenStatic
Specify the location of the XSL file
var stylefile = Server.MapPath ("simple.xsl");
Save the XML to XMLDOM
var Source = Server.CreateObject ("Microsoft.XMLDOM");
' Rsxml.save source, adPersistXML
"I rather dislike the XML document that ADO directly save, I always do:
Dim getdata,v
GetData = GetData & "<bbs>"
While not rs_foruminfo.eof
GetData = GetData & "<post>"
For i = 0 to Rs_foruminfo.fields.count-1
Set v = RS_ForumInfo.Fields.Item (i)
if (v.type=201) or (v.type=203) or (v.type=205) then
GetData = getdata& "<" & RS_ForumInfo.Fields.Item (i). Name & ">" &_
"<! [Cdata[& RS_ForumInfo.Fields.Item (i). Value & "]]>" &_
"</" & RS_ForumInfo.Fields.Item (i). Name & ">"
Else
GetData = getdata& "<" & RS_ForumInfo.Fields.Item (i). Name & ">" &_
RS_ForumInfo.Fields.Item (i). Value &_
"</" & RS_ForumInfo.Fields.Item (i). Name & ">"
End If
Set V = Nothing
Next
GetData = GetData & "</post>"
Rs_foruminfo.movenext
Wend
GetData = GetData & "</bbs>"
Source.loadxml GetData
Load the XSL
var style = Server.CreateObject ("Microsoft.XMLDOM");
Style.async = false;
Style.load (Stylefile);
Response.Write (Source.transformnode (style));
%>
Of course, because it is easy to use ADO directly to generate XML, simple.xsl is different from the b.xsl above.
The reader can refer to the above example and XSL reference (the 2000 MSDN has a more detailed xml/xsl SDK documentation) to write. Finish

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.