Hi
I have some C# code that loops through an XMLDocument and needs to
apply an XSLT stylesheet to each node in the XML document.
My (simplified) code looks like this:
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(filename);
XmlNodeList nodeliste =
xmldoc.SelectNodes("/*[local-name()='Guideline' and
namespace-uri()='ns']/*[local-name()='ABIE' and
namespace-uri()='ns']");
foreach (XmlNode node in nodeliste)
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = "\t";
settings.Encoding = Encoding.UTF8;
settings.OmitXmlDeclaration = true;
settings.ConformanceLevel = ConformanceLevel.Fragment;
StringBuilder createdContent = new StringBuilder();
XmlWriter writer;
writer = XmlWriter.Create(createdContent, settings);
XmlUrlResolver resolver = new XmlUrlResolver();
XslCompiledTransform transform = new XslCompiledTransform(true);
transform.Load(@"XMLtoHTML.xsl", XsltSettings.TrustedXslt, resolver);
XsltArgumentList arguments = new XsltArgumentList();
arguments.AddParam("country", "", country);
transform.Transform(tempFilename, arguments, writer);
}
If I run this code, the output from the transform method is the
innertext of the XmlNode given to the transform method. And NOT the
output I expected :-)
If I, however, create a new XmlDocument, load it with the
node.OuterXml and save this XmlDocument to disc, then the transform
method produces the correct output, given the new filename as input
instead of the XmlNode.
I'd really like not to ahve to write the node to disc before
performing the transformation.
Can anyone help me with that?
--
eliasen, representing himself and not the company he works for.
Private blog: http://blog.eliasen.dk
Private email: ja*@eliasen.dk