Generating HTM pages with XML and XSLT is what I always want to do,
After all, instead of making the ASPX page access the database every time it accesses the database, open the data connection, and close the data connection,
It is better to save data as an HTM static page.
I have been searching for this information on the Internet. I also went to msdn to look at the class library, one method and one method, and finally managed to gain a glimpse.
Come on!
Three files are required: XML, XSL, and Aspx.Program
Listing8.8.2.xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Golfers>
<Golfer skill = "excellent" handicap = "10" clubs = "Taylor made" id = "1111">
<Name>
<Firstname> Bu qingcloud </firstname>
<Lastname> Frey </lastname>
</Name>
</Golfer>
<Golfer skill = "moderate" handicap = "12" clubs = "Taylor made" id = "2222">
<Name>
<Firstname> Frey </firstname>
<Lastname> Glenn </lastname>
</Name>
</Golfer>
</Golfers>
listing8.8.1.xsl
my name:
.
Finally, the aspx program page listing8.5.aspx
<% @ Import namespace = "system. xml" %>
<% @ Import namespace = "system. xml. XSL" %>
<% @ Import namespace = "system. xml. XPath" %>
<% @ Import namespace = "system. Io" %>
<Script language = "VB" runat = "server">
Public sub page_load (sender as object, e as eventargs)
Dim xmlpath as string = server. mappath ("listing8.2.xml ")
Dim export path as string = server. mappath ("listing8.1.xsl ")
Dim htmpath as string = server. mappath ("listing8.1.htm ")
Dim FS as filestream = new filestream (xmlpath, filemode. Open, fileaccess. Read)
Dim reader as streamreader = new streamreader (FS, encoding. utf8)
Dim xmlreader as xmltextreader = new xmltextreader (Reader)
Dim fstr as filestream = new filestream (htmpath, filemode. Create)
Dim doc as xpathdocument = new xpathdocument (xmlreader)
Dim ‑doc as ‑transform = new ‑transform ()
Using Doc. Load (using path)
'Convert data
Using Doc. Transform (Doc, nothing, fstr, nothing)
Export Doc. Transform (Doc, nothing, response. Output) ''output to the page
'Close the opened object
FS. Close ()
Reader. Close ()
Xmlreader. Close ()
Fstr. Close ()
End sub
</SCRIPT>
The generated HTM file is as follows ::
Listing8.8.1.htm
<HTML>
<Body>
<B> what about me: </B>
<Br> 1.
Bu qingcloud <br> 2.
Frey </body>
</Html>