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.