Some time ago, I accidentally saw a blog's RSS that can be output in XSL format and can be browsed in Firefox. I thought that an XML guestbook I wrote before was left unresolved because it was incompatible with Firefox. Now I saw that his guestbook could be browsed in Firefox. I looked at the code and compared it sentence by sentence. Finally, I finally found the reason and completed the guestbook. Because it is a simple XML guestbook, it is named SXGB (Simple XML GuestBook).
Leave a message book demonstration, the management password is test: http://home.goofar.com/hotheart/gbook/gbook.asp
First, define the format of the XML document in the guestbook. As a guest book, there is no need for too complicated content, so I divided the message content into 3 parts: the name of the commentator, the homepage of the commentator and the content of the message. In addition, a guest book also requires some information about the user, including the user name and user homepage. In addition, when you leave more messages, you need to paginate information. After the rough structure is completed, you can start writing XML document templates.
The root element of the XML document is defined as a gbook
XML document template gbook.xml
CODE:
xml version="1.0" encoding="utf-8"?>
<!-- DTD file -->
<!DOCTYPE gbook SYSTEM "sxgb.dtd">
<!-- XSL file -->
<?xml-stylesheet type="text/xsl" href="gbook.xsl"?>
<gbook>
<!-- Related information of the guest book-->
<info>
<!-- Username-->
<user>HotHeart</user>
<!-- User Home Page-->
<home>http://www.xujiwei.cn</home>
<!-- The page information is the current page, the total number of pages, the previous page, the next page-->
<pagenow>1</pagenow>
<pagetotal>1</pagetotal>
<pageprev>1</pageprev>
<pagenext>2</pagenext>
<!-- Whether it has been logged in, used to deal with whether to display the login box-->
<logined>NO</logined>
</info>
<!-- Message List-->
<messages>
<!-- A message-->
<message>
<!-- Message ID -->
<id>1</id>
<!-- The name of the commenter-->
<username>Admin</username>
<!-- Message time-->
<time>2005-08-09 12:00</time>
<!-- Messager's Home Page-->
<homepage>http://www.xujiwei.cn/</homepage>
<!-- Message content-->
<content><![CDATA[ Message Content]]></content>
</message>
</messages>
</gbook>
Be careful not to use when referring to XSL
<?xml:stylesheet type="text/xsl" href="gbook.xsl"?>
A bar (-) should be used between xml and stylesheet instead of colon (:). Colon is not supported in Firefox.
A good XML document should be not only structural, but also valid. Therefore, the document type definition (DTD) sxgb.dtd is defined at the beginning of the XML document. Let’s complete the definition of this document type. Because the structure of the guestbook XML document has been designed, it is very convenient to write DTD.
Document type definition sxgb.dtd
CODE:
<?xml version="1.0" encoding="utf-8"?>
<!ELEMENT gbook (info,messages)>
<!ELEMENT info (user,home,msgtotal,pagenow,pagetotal,pageprev,pagenext,logined)>