Transfrom Memory XML and send output to client

So i am loading a base XML file. Modify this file in the memory, load an XSL that should convert it to a nice HTML page.

however, i have no clue as to how i can send the transfrom results to the client!

here is what im doing:

//the classes
public abstract class XMLWorker
{
protected XmlDocument xmlDoc = new XmlDocument();

protected XMLWorker()
{
}
}
public sealed class XMLPageCore : XMLWorker
{
public XMLPageCore(string Path2BaseXML)
{
xmlDoc.Load(Path2BaseXML);
XmlElement selectedNode = (XmlElement)xmlDoc.DocumentElement.Selec
tSingleNode("General/Now");
}
public void Deploy(string XSLTPath,System.IO.Stream Stream)
{
System.Xml.Xsl.XslCompiledTransform XSLT = new System.Xml.Xsl.XslCompiledTransform();
default: XSLT.Load(XSLTPath);
System.Xml.Xsl.XsltArgumentList args=new System.Xml.Xsl.XsltArgumentList ();
XSLT.Transform(xmlDoc.DocumentElement,args,Stream);
}
}

//The call

XMLPageCore test = new XMLPageCore(Server.MapPath("test/XMLFile.xml"));
test.Deploy(false,Server.MapPath("test/XSLTFile.xsl"),Response.OutputStream);



on the page though, i get the XML Processing Instructions < .. and then all of the xml content w/o any tags or whitespace.

but if i use the overload of xslt.transform that will take the input and output files as parameter, it works just fine.

to be honest im really at a bit of a loss as to what is going on here!



Answer this question

Transfrom Memory XML and send output to client

  • James Grant

    XslCompiledTransform starts transformation from element you passed to it comparing to XslTransform which always starts from root node.

    As a result <template match="/" > never matches any nodes. And default template rules copy all text nodes of your source document to output.

    You can find some details on Introducing XslCompiledTransform.

    To fix this in your code call:
    XSLT.Transform(xmlDoc,args,Stream);
    instead of
    XSLT.Transform(xmlDoc.DocumentElement,args,Stream);

    (I didn't verify the fix, but it seams that this is the issue.)



  • t_girl

    This is UTF-8 byte order mark. you can ignore it.


  • pravin333

    ok it works now that i use response.outputstream instead of response.output, BUT i get 3 funky symbols at the very top of the document

    i  <!DOCTYPE htm





  • Flaatten

    Writing the XSL otutput to the Response.OutputStream should work fine, so I would debug whether this code is executing using debugger and whether the xsl is actually producing any output. You might also need to set the Response.ContentType to text/html.
  • BusmasterJones

    got the transform working, but i can not get the DTD in the output.

    the xsl:output node seems to be ignored by the transfrom.


  • Tom Majarov

    no i cant becasuse it shows up on every singe place, and it wont validate either.

    there must be a way to get rid of it!


  • Transfrom Memory XML and send output to client