Linda Smith asks: How do use XSLT stored in a string for an XSLT transformation?

The System.IO.StringReader class is often overlooked for situations like this. The System.IO.StringReader class derives from System.IO.TextReader: any overload versions of a method that accept a TextReader will also accept a StringReader.

private void Page_Load(object sender, System.EventArgs e)
{
System.Xml.Xsl.XslTransform trans = new System.Xml.Xsl.XslTransform();
System.IO.StringReader reader = new System.IO.StringReader(getXSLT());
trans.Load(new System.Xml.XPath.XPathDocument(reader));

System.Xml.XmlTextReader xmlreader = new System.Xml.XmlTextReader(Server.MapPath("xmlfile1.xml"));
trans.Transform(new XPathDocument(xmlreader),null,Response.OutputStream);
reader.Close();
xmlreader.Close();
}
private string getXSLT()
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<?xml version='1.0'?><?xml:namespace prefix = xsl /><xsl:stylesheet 
sb.Append(?xmlns:xsl="http://www.w3.org/1999/XSL/Transform" ?); version="1.0">");
sb.Append("<xsl:template match="*">");
sb.Append("<xsl:copy><xsl:apply-templates select="*"></xsl:apply-templates>");
sb.Append("</xsl:copy></xsl:template></xsl:stylesheet>");
return(sb.ToString());
}