Does this do what you want?
--begin code--
using System.Xml;
public class XmlWriterTest {
public static void Main() {
System.Console.WriteLine("\n\n");
string filename= "Sample.xsl";
string xsltns= "http://www.w3.org/1999/XSL/Transform";
XmlTextWriter xwriter = new
XmlTextWriter(filename,System.Text.Encoding.UTF8);
xwriter.Formatting = Formatting.Indented;
xwriter.WriteStartDocument(true);
xwriter.WriteStartElement("xsl", "stylesheet",xsltns);
xwriter.WriteAttributeString("version", "1.0");
xwriter.WriteStartElement("output",xsltns);
xwriter.WriteAttributeString("method", "xml");
xwriter.WriteAttributeString("indent", "yes");
xwriter.WriteAttributeString("encoding", "UTF-8");
xwriter.WriteEndElement(); // output
xwriter.WriteStartElement("template",xsltns);
xwriter.WriteAttributeString("match", "text()|@*");
xwriter.WriteEndElement(); // template
xwriter.WriteStartElement("template",xsltns);
xwriter.WriteAttributeString("match", "AdvanceShipmentNotice");
xwriter.WriteStartElement("root","");
xwriter.WriteStartElement("apply-templates",xsltns);
xwriter.WriteEndElement(); // root
xwriter.WriteEndElement(); // xsl-template
xwriter.WriteStartElement("template",xsltns);
xwriter.WriteAttributeString("match", "Rabble");
xwriter.WriteStartElement("value-of",xsltns);
xwriter.WriteAttributeString("select", "Ident");
xwriter.WriteEndElement(); // value-of
xwriter.WriteEndElement(); // template
// and so on with other xsl-template elements ....
xwriter.WriteEndElement(); // stylesheet
xwriter.Flush();
xwriter.Close();
//Read the file back in and parse to ensure well formed XML.
XmlDocument doc = new XmlDocument();
//Preserve white space for readability.
doc.PreserveWhitespace = true;
//Load the file
doc.Load(filename);
//Write the XML content to the console.
doc.Save(System.Console.Out);
System.Console.WriteLine("\n\n");
}
}
--end code--
-Dino
"Harry Keck" <Ha*******@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
As a follow up, I tried the version of CreateElement that requires a
namespace as a parameter. When I pass a namespace, the element's "xsl"
prefix shows up the way that I want it, but now I have the namepace tag in
my
"xsl:value-of" element, which, again, messes up the transform. Is there a
solution that will produce the prefix without the namespace attribute?
"Harry Keck" wrote:
I am trying to create an xsl stylesheet on the fly as an xml document. I
create elements of type "xsl:value-of" and insert them into my document,
but
when I output the xml representation of the document, the "xsl" prefix is
not
there, only the "value-of" is present, so my transform does not work.
What
do I need to do to get the prefix to become part of the xml output? I
have
even tried using the CreateElement version with a separate prefix and
local
name parameters, but it did not change anything. Thanks.