Use XML and XSLT to generate static html pages

Source: Internet
Author: User
Tags xsl xslt
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>

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.