I am new to XSLT Transformation world. I’m using XSLT to create an HTML file. How can I get the output as string, so that I can save it to an HTML file?
Performing the transformation using below line:
objXtrans.Transform(objDoc, objArgLists, objXmlTxtWriter);
How can I convert objXmlTxtWriter to get the complete string generated via the Transform() method which can be saved as HTML?
If you want the transformation result to be a HTML file then transform to a file (stream), there is no need to first assemble a string in memory to write that complete string to a file.
Unfortunately you have not really told us which API you use, you mention XmlTextWriter in your subject line so I assume it is the .NET framework you use. Since .NET 2.0 the preferred XSLT processor is System.Xml.Xsl.XslCompiledTransform, if you look at its Transform method then it has several overloads transforming to a Stream so you could simply use code as follows:
You have a lot of options for the first argument, it can simply be a string with an input file name or URI, it can be an XmlReader, it can be an object implementing IXPathNavigable (such as an XmlDocument or XPathDocument).