Generate HTML files according to XSLT definition XML files

Source: Internet
Author: User
Tags xsl xslt
The HTML file generated according to the XML file defined by XSLT has the following xls file: <! --
-XSLT is a template based language to transform XML documents ents
It uses XPath to select specific nodes
For processing.

-A xslt file is a well formed XML document
-->

<! -- Every stylesheet starts with this tag -->
<XSL: stylesheet
Xmlns: XSL = "http://www.w3.org/1999/XSL/Transform"
Version = "1.0">
<! -- Indicates what our output type is going to be -->
<XSL: output method = "html"/>
<! --
Main template to kick off processing our sample. xml
From here on we use a simple XPath selection query
Get to our data.
-->
<XSL: template match = "/">
<HTML>
<Head>
<Title> welcome to <XSL: value-of select = "/Company/Name"/> </title>
<Style>
Body, TD {font-family: tahoma, Arial; font-size: 9pt ;}
</Style>
</Head>
<Body>
<H2> welcome to <XSL: value-of select = "/Company/Name"/> </H2>
<P/>
<B> our contact details: </B>
<Br/>
<Br/>
<XSL: value-of select = "/Company/Name"/>
<Br/>
<XSL: value-of select = "/Company/address1"/>
<Br/>
<XSL: value-of select = "/Company/address2"/>
<Br/>
<XSL: value-of select = "/Company/City"/>
<Br/>
<XSL: value-of select = "/Company/Country"/>
</Body>
</Html>
</XSL: Template>
</XSL: stylesheet>

The XML file is as follows: <company>
<Name> XYZ Inc. </Name>
<Address1> one ABC way </address1>
<Address2> some avenue </address2>
<City> tech city </city>
<Country> Neverland </country>
</Company>

The two files are named sample. XSL and sample. xml respectively.
C # code: public static void transform (string sxmlpath, string sxslpath)
{

Try
{

// Load the XML Doc
Xpathdocument myxpathdoc = new xpathdocument (sxmlpath );

Inclutransform mydomaintrans = new inclutransform ();

// Load the XSL
Mydomaintrans. Load (sdomainpath );

// Create the output stream
Xmltextwriter mywriter = new xmltextwriter
("Result.html", null );

// Do the actual transform of XML
Mydomaintrans. Transform (myxpathdoc, null, mywriter );

Mywriter. Close ();


}
Catch (exception E)
{

Console. writeline ("exception: {0}", E. tostring ());
}

}

Generate result.html as follows: <HTML>
<Head>
<Title> welcome to XYZ Inc. </title>
<Style>
Body, TD {font-family: tahoma, Arial; font-size: 9pt ;}
</Style>
</Head>
<Body>
<H2> welcome to XYZ Inc. </H2>
<P/>
<B> our contact details: </B>
<Br/>
<Br/>
XYZ Inc.
<Br/>
One ABC way
<Br/>
Some Avenue
<Br/>
Tech City
<Br/>
Neverland
</Body>
</Html>

In this way, the page can be generated
It is mainly because XLS needs to be well studied.

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.