all groups > dotnet xml > august 2005 >
You're in the

dotnet xml

group:

Transform Method on Demand.


Transform Method on Demand. K riley
8/31/2005 3:04:49 PM
dotnet xml:
Hi.

I am using the transform method to create an HTML file using an existing XML Document and an XLST. I need to use XPath to extract
a node from my XML Document and my XLST document will format the node into something readable to my users.

My code works, however, I will be having multiple users calling my routines at the same time. So I don't want to create a "hard"
copy of my html file and place on my server. Because every time a new user calls the routine it will overwrite the html file.
I'd rather have the html file be virtual on each users web browser.

My question is, I'm not sure where I need to change my code. I have tried several variations of the XslTransform sending
different parameters but nothing is getting me the desired result. And I am unsure if it is my XslTranform call, or if I need to
change my writer class or if my webform actually needs additional objects to "virtually" display the html file. I am at a lose as
to where I look for the answer.

Thank you in advance for any help. Below please find my code behind for my form that actually creates an HTML file on my web server.

//Read in textbox value
string userInput = TextBox1.Text.Trim();

// Create a resolver with default credentials.
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;
XslTransform xslt = new XslTransform();
xslt.Load(Server.MapPath("XSLTFile.xsl"),resolver);

XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("XMLFile.xml"));

//Get Node 1
XmlNodeList N1NodeList = doc.DocumentElement.SelectNodes("//N1");
XmlNode N1 = N1NodeList.Item(0);

//using XPath to search a node for the user Inputted Value
string y = "//N2[N2C1 = '" + userInput + "']";
XmlNodeList testNodeList = doc.DocumentElement.SelectNodes(y);

string x = testNodeList.Count.ToString(); // If NodeList exists
int i = testNodeList.Count;

if (i >= 1) //need to throw error if group id is not found.
{
XmlNode testNode = testNodeList.Item(0);

//Move within the tree.
testNode.PrependChild(busDate);

XmlDocument tmpDoc = new XmlDocument();
tmpDoc.LoadXml(testNode.OuterXml);


// Now big question. Multi-threading - multiple users -- writing a file to system. Rather have it dynamic.
XmlTextWriter writer = new XmlTextWriter(Server.MapPath("asucPartial.html"), null);
xslt.Transform(tmpDoc,null,writer,resolver);
writer.Close();

Label1.Text = "done";

}
else
{
x = "Record Not Found.";
Label1.Text = x;
}
Re: Transform Method on Demand. Pascal Schmitt
9/1/2005 12:00:00 AM
Hello!

[quoted text, click to view]

Just write it to Response.OutputStream if you're using ASPX or ASHX. It
will be directly sent to the client.



--
Re: Transform Method on Demand. K riley
9/1/2005 9:24:30 AM

THANK YOU.

[quoted text, click to view]
AddThis Social Bookmark Button