Home
Manage Your Code
Snippet: XSLT Transform from string (C#)
Title: XSLT Transform from string Language: C#
Description: This code transforms a string based snippet of xslt to a new xml structure Views: 1924
Author: Kevin Isom Date Added: 10/14/2008
Copy Code  
1string xslMarkup = @"<?xml version='1.0'?>
2<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0' >
3<xsl:output method='html' indent='yes' />
4<xsl:template match='/'>
5!-- Do XSLT Here -->	 
6
7    </xsl:template>
8</xsl:stylesheet>";
9
10XDocument source = new XDocument(Content);
11
12
13XDocument newTree = new XDocument();
14using (XmlWriter writer = newTree.CreateWriter())
15{
16	// Load the style sheet.

17	XslCompiledTransform xslt = new XslCompiledTransform();
18	xslt.Load(XmlReader.Create(new StringReader(xslMarkup)));
19	// Execute the transform and output the results to a writer.

20	xslt.Transform(source.CreateReader(), writer);
21}
22