20.01.2015 Views

Teach Yourself e.net - Syspro

Teach Yourself e.net - Syspro

Teach Yourself e.net - Syspro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

More Advanced Options<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

In order to transform Chapter.xml into an HTML document using Chapter.xsl we<br />

need to load both files into an XSLT processor. We can do this using a simple ASP.NET<br />

program, as demonstrated using the code shown below:<br />

Example 6.5. ASP.NET C# using the XslTransform Class<br />

<br />

<br />

<br />

<br />

public void Page_Load(Object sender, EventArgs E) {<br />

string xmlPath = Server.MapPath("Chapter.xml");<br />

string xslPath = Server.MapPath("Chapter.xsl");<br />

//Instantiate the XPathDocument Class<br />

XPathDocument doc = new XPathDocument(xmlPath);<br />

//Instantiate the XslTransform Class<br />

XslTransform transform = new XslTransform();<br />

transform.Load(xslPath);<br />

//Custom format the indenting of the output document<br />

//by using an XmlTextWriter<br />

XmlTextWriter writer=new XmlTextWriter(Response.Output);<br />

writer.Formatting = Formatting.Indented;<br />

writer.Indentation=4;<br />

transform.Transform(doc, null, writer);<br />

}<br />

<br />

6–7

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!