[Reprint] use XML and XSLT to generate static html pages

Source: Internet
Author: User
Tags xsl xslt
Reposted from: success,
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> C # Code : Code
String Xmlpath = Server. mappath ( " Listing. xml " );
String Export path = Server. mappath ( " Listing. XSL " );
String Htmlpath = Server. mappath ( " Listing.htm " );

Filestream FS =   New Filestream (xmlpath, filemode. Open, fileaccess. Read );
Streamreader =   New Streamreader (FS, encoding. utf8 );
Xmltextreader xmlreader =   New Xmltextreader (Reader );
Filestream fstr =   New Filestream (htmlpath, filemode. Create );

xpathdocument xpathdoc = New xpathdocument (xmlreader );
compile compiledtransform transform = New extends compiledtransform ();
transform. load (export path);

transform. transform (xpathdoc, null , fstr);
/// transform. transform (xpathdoc, null, response. output);

FS. close ();
reader. close ();
xmlreader. close ();
fstr. close ();

the generated HTM file is as follows:
listing8.1.htm


what does my name mean:
1.
Bu qingcloud
2.
Frey

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.