System.Xml.Xsl is a package library in C# used for transforming XML data using XSLT. The package provides an XslCompiledTransform class that represents an XSLT compilation and transformation.
Example 1: Transform XML document using XSLT
// Load the XML document and the XSLT document XmlDocument doc = new XmlDocument(); doc.Load("input.xml"); XslCompiledTransform xslt = new XslCompiledTransform(); xslt.Load("transform.xsl");
// Create a StringWriter to store the output StringWriter result = new StringWriter();
// Transform the XML document and output the result xslt.Transform(doc, null, result); Console.WriteLine(result.ToString());
This example loads an XML document and an XSLT document, and then transforms the XML document using the XSLT. The output is stored in a StringWriter and then printed to the console.
Example 2: Apply XSLT transformation to XML file and output to HTML file
// Load the XML document and the XSLT document XmlDocument doc = new XmlDocument(); doc.Load("input.xml"); XslCompiledTransform xslt = new XslCompiledTransform(); xslt.Load("transform.xsl");
// Transform the XML document and output the result using (XmlWriter writer = XmlWriter.Create("output.html", xslt.OutputSettings)) { xslt.Transform(doc, null, writer); }
This example loads an XML document and an XSLT document, and then uses them to transform the XML document and output the result to an HTML file. The XSLT.OutputSettings property is used to specify the output format of the transformation.
C# (CSharp) System.Xml.Xsl XslCompiledTransform - 60 examples found. These are the top rated real world C# (CSharp) examples of System.Xml.Xsl.XslCompiledTransform extracted from open source projects. You can rate examples to help us improve the quality of examples.