I found the answer to my problem. If I perform the transform using the .NET framework classes instead of the SQLXML managed classes, I can use the XmlTextWriter to control the indentation.
public static string ExecuteQueryAndTransform(string connectionString, string queryText, string xslPath)
{
string result = String.Empty;
SqlXmlCommand cmd = new SqlXmlCommand(connectionString);
if (!queryText.EndsWith("For XML Auto", StringComparison.CurrentCultureIgnoreCase))
{
queryText += " For XML Auto";
}
cmd.RootTag = "Root";
cmd.CommandText = queryText;
using (Stream strm = cmd.ExecuteStream())
{
XmlTextReader reader = new XmlTextReader(strm);
XPathDocument xd = new XPathDocument(reader, XmlSpace.Preserve);
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(xslPath);
StringWriter stringWriter = new StringWriter();
XmlTextWriter writer = new XmlTextWriter(stringWriter);
writer.Formatting = Formatting.Indented;
writer.Indentation = 3;
writer.IndentChar = ' ';
xslt.Transform(xd, null, writer);
result = stringWriter.ToString();
}
}
Thanks for your help anyway.
Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush