How to XSL-transform documents into a place-holder on the form?

V

vitaly.tomilov

I'm using an ASP.NET form to display data from my database table, and
I'm doing it in the following way:

XmlDataDocument doc = new XmlDataDocument(mydataSet);
XPathNavigator nav = doc.CreateNavigator();
XslTransform xslTran = new XslTransform();
xslTran.Load("Transform.XSL");
xslTran.Transform(nav, null, Response.Output, null);

This produces me a nice HTML page with enhanced formatting specified
within Transform.XSL, and streams the result into the output.

The problem is the result is written into the output without any
control of where and how it will be formatted. I want to use some sort
of a place-holder that I could visually place on the form at design
time to set sizes and align with other UI elements on the form.
The question is - what could be such a place-holder into which I
could redirect all the output, and how can I use it?
Method Transform writes out into a stream, so, whatever place-holder
must expose its stream object or something, methinks....

Anyways,
- Suggested by some people control System.Web.UI.WebControls.Xml
won't do, as it doesn't support XSL formatting.
- Writing resulting HTML into a file and then reading it in as mere
text - sounds more like a nonsense.

Other than that, I gave up looking...

Please somebody help me!!!
 
G

Gerhard Pretorius

I got it right with this code:

In aspx
<asp:Xml ID="Xml1" runat="server" EnableViewState="False"
TransformSource="~/Dealer/DealerMaster.xsl" Visible="False"></asp:Xml>

In C#

private void ShowDealer(string dealerID)
{

lblMessage.Text = "";

try

{

string commandText = string.Format("exec Dealer_Master_XSP_DealerID
@DealerID={0}", dealerID);

string connect =
ConfigurationManager.ConnectionStrings["OperationsSqlXmlConnectionString"].ConnectionString;

Xml1.Visible = true;

Xml1.XPathNavigator = XPathXML(connect, commandText);

Xml1.TransformSource = "DealerMaster.xsl";

}

catch (Exception ex)

{

lblMessage.Text = ex.Message;

}

}

private System.Xml.XPath.XPathNavigator XPathXML (string connectionString,
string commandText)

{

SqlXmlCommand mySqlXmlCommand = new SqlXmlCommand(connectionString);

mySqlXmlCommand.RootTag = "root";

mySqlXmlCommand.CommandType = SqlXmlCommandType.Sql;

mySqlXmlCommand.CommandText = commandText;

XmlReader xmr = mySqlXmlCommand.ExecuteXmlReader();

System.Xml.XPath.XPathDocument xpd = new
System.Xml.XPath.XPathDocument(xmr);

return xpd.CreateNavigator();

}
 
V

vitaly.tomilov

So, to go through this step-by-step,...

Instead of setting DocumentSource with XML contents, you set property
XPathNavigator. First off, XML control in ASP.NET doesn't have
property XPathNavigator, so I don't understand how this even
compiles...

I don't quite understand the meaning of each line in method XPathXML,
but it looks like you're using SQL Server natural XML data
presentation, and then something else... I'm using both SQL and JET
databases, so cannot quite use the suggested technique...

Your methodology doesn't allow for any transformation parameters like
we can pass in method Transform of XslTransform. I'm using such to
pass parameters-objects for data columns pre-processing.

On the overall, doesn't seems feasible to be adapted to my needs.

I appreciate the answer anyway, thank you.

Anyone can throw in not as controversial an example?

Cheers!
 
B

Bruce Barker

don't pass the response stream to transform, pass a string stream, then you
can pass the string to a passholder.

StringWriter sr = new StringWriter();
XmlDataDocument doc = new XmlDataDocument(mydataSet);
XPathNavigator nav = doc.CreateNavigator();
XslTransform xslTran = new XslTransform();
xslTran.Load("Transform.XSL");
xslTran.Transform(nav, null, sr, null);

HtmlGenericControl ctl = new HtmlGenericControl("div");
ctl .InnerHtml = sr.ToString();
Page.Controls.Add(ctl); // or add to a placeholder


-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top