Let's say I have two strings:
- one is XML data
- and the other is XSL data.
The xml and xsl data are stored in database columns, if you must know.
How can I transform the XML in C# w/o saving the xml and xsl as files first? I would like the output to be a string, too (HTML from the transformation).
It seems C# prefers to transform via files. I couldn't find a string-input overload for Load() in XslCompiledTransform. So, that's why I'm asking.
I send the xml content and then load the XSLT document, apply the transformation and then return the new xml.
NOTE: "XSLTFile.xslt" It is added to the solution and set the property "Copy to Output Directory" to "Copy always".
Here's what I went with. It's a combination of your answers. I voted up the answers that inspired this:
Note: this statement is required in the xsl, in order to output as HTML:
You can XmlReader.Create() from a StringReader or a MemoryStream . XslCompileTransfrom can Load() from an XmlReader.
A VB.Net version inspired by Robert Rossney's answer:
I would use the
XmlReader.Create(DatabaseBlobStream)
andXmlWriter.Create(StringBuilder)
overloads. Using the following DatabaseBlobStream objectDatabaseBlobStream.cs
edit: using-blocks added