<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Garkbit Blog &#187; .NET 3.5</title>
	<atom:link href="http://wp.garkbit.com/tag/net-3-5/feed/" rel="self" type="application/rss+xml" />
	<link>http://wp.garkbit.com</link>
	<description>... on the other side of the universe</description>
	<lastBuildDate>Fri, 22 Oct 2010 14:16:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Transforming XML/XSLT using .NET 3.5</title>
		<link>http://wp.garkbit.com/2009-12-14/transforming-xmlxslt-using-net-3-5/</link>
		<comments>http://wp.garkbit.com/2009-12-14/transforming-xmlxslt-using-net-3-5/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 13:27:35 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[ASP.NET/C#]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[XML/XSLT]]></category>
		<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://wp.garkbit.com/?p=200</guid>
		<description><![CDATA[Here is a simple example of how you can apply a XSLT stylesheet to a XML file and deliver the result to the browser using ASP.NET 3.5. default.aspx.cs Yes, that&#8217;s it! Here below are the rest of the code used to complete a fully working demo. default.aspx hello-world.xml hello-world.xslt Tip! To have the HTML doctype [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a simple example of how you can apply a XSLT stylesheet to a XML file and deliver the result to the browser using ASP.NET 3.5.</p>
<p><strong>default.aspx.cs</strong></p>
<pre class="brush: csharp; title: ; notranslate">
using System;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;

public partial class _default : System.Web.UI.Page {

    protected void Page_Load(object sender, EventArgs e) {

        // Source paths
        string xmlFilePath = Server.MapPath(&quot;hello-world.xml&quot;);
        string xsltFilePath = Server.MapPath(&quot;hello-world.xslt&quot;);

        // Load XML
        XPathNavigator nav = new XPathDocument(new XmlTextReader(xmlFilePath)).CreateNavigator();

        // Stream for the transformed XML
        MemoryStream stream = new MemoryStream();

        // Load XSLT &amp; transform
        XslCompiledTransform transformer = new XslCompiledTransform();
        transformer.Load(xsltFilePath);
        transformer.Transform(nav, null, stream);

        // Write output
        using (StreamReader reader = new StreamReader(stream)) {
            stream.Position = 0;
            Response.Write(reader.ReadToEnd());
            reader.Close();
        }

    }

}
</pre>
<p>Yes, that&#8217;s it! Here below are the rest of the code used to complete a fully working demo.</p>
<p><strong>default.aspx</strong></p>
<pre class="brush: xml; title: ; notranslate">

&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;default.aspx.cs&quot; Inherits=&quot;_default&quot; %&gt;
</pre>
<p><strong>hello-world.xml</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?&gt;
&lt;?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;hello-world.xslt&quot;?&gt;
&lt;text&gt;Hello World!&lt;/text&gt;
</pre>
<p><strong>hello-world.xslt</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?&gt;
&lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt;
  &lt;xsl:output indent=&quot;yes&quot; /&gt;
  &lt;xsl:output method=&quot;html&quot;/&gt;

  &lt;xsl:template match=&quot;/&quot;&gt;
&lt;xsl:text disable-output-escaping=&quot;yes&quot;&gt;
&amp;lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&amp;gt;
&lt;/xsl:text&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
  &lt;head&gt;
    &lt;title&gt;&lt;xsl:value-of select=&quot;text&quot;/&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;h1&gt;&lt;xsl:value-of select=&quot;text&quot;/&gt;&lt;/h1&gt;
  &lt;/body&gt;
&lt;/html&gt;
  &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;
</pre>
<p><strong>Tip!</strong> To have the HTML doctype declared in your XSLT document you need to wrap it in a <em>&lt;xsl:text&gt;</em> tag with the <em>disable-output-escaping</em> attribute set to <em>yes</em>. And don&#8217;t forget to swap the leading and tailing <em>&lt;</em> and <em>&gt;</em> for <em>&amp;lt;</em> and <em>&amp;gt;</em>.</p>
<p><strong>Output</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
  &lt;head&gt;
    &lt;title&gt;Hello World!&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;h1&gt;Hello World!&lt;/h1&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://wp.garkbit.com/2009-12-14/transforming-xmlxslt-using-net-3-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

