looking at the XSLCompiledTransform Class in .NET at trying to find a concise way to use it in F#. I am unfamiliar with string readers/writers but am looking at that as primary method to accomplish this. Or do I want XML readers?
I have a function that will take two arguments - an XML string and an XSLT stylesheet. I want to return a string of XML.
let applyXSLTransform xml xslFile =
let xslt = XslCompiledTransform()
xslt.Load(xslFile)
xslt.Transform(xml, outputToString); //This bit
It's nice and easy to do with files but seems a bit more involved to read and write to strings. I have seen a few C# samples and not having immediate success in getting them to work so still doing research onto readers and writers!
Cheers
I don't think there is an easier way to use the API than using the
XmlReaderandXmlWriterinterfaces. This is unfortunately quite tedious, but the following should do the trick:The code constructs
StringBuilder, which is an in-memory object for constructing strings. It wraps this aroundStringWriterandXmlTextWriterto be passed to theTransformmethod. At the end, you read the contents of theStringBuilderusing theToStringmethod. Similar thing happens to createXmlTextReaderfor data fromStringReader, which contains your input XML.