XML, XSL and ASP.Net

  • Thread starter Thread starter djamilabouzid
  • Start date Start date
D

djamilabouzid

Hi,

I am wondering if someone can help me. This will be very grateful. Here
is an explanation of my problem:

o I have collections in SQL Server 2005 database
o I search these collections by keywords
o I collect the search results in an XML
o I use XSL for the layout of my results
o I display the results by 9 items.

My question is the following:

As I program in ASP.Net, I would like to know if there is a way to link
my XML variable that I generate dynamically (with the database results)
to XSL file trough ASP.Net. I know that this solution exists in PHP but
I couldn't find its equivalent in ASP.Net.
Otherwise, is there another way to resolve this problem?

Thank you very much for your response,

Djamila.
 
Hi,
you can use XmlDataSource control, this control can load xml from file or
string, and can apply any transform you specify
Regards,
Mohamed Mosalem
 
Thank you for your response.

I would like to tell you that I am not using visual Studio .Net for my
program. And I did a search in the Internet for XMLDataSource control,
and all examples that I find are using files, like that :

<asp:XmlDataSource ID="XmlDataSource" runat="server"
DataFile="~/XMLFile.xml"
XPath="IranHistoricalPlaces/Place">
</asp:XmlDataSource>

So I don't know how to use variable (for XML object) in
XMLDataSource.

Could you please give me an example with a variable? That can be very
helpful.


Regards,

Djamila.
 
Hi Djamila,
You can bind the XmlDataSource control to xml file (as in the example you
provided) or to xml string directly as shown below

<asp:XmlDataSource ID="xmlDS" runat="server"
XPath="IranHistoricalPlaces/Place">
</asp:XmlDataSource>

xmlDS.Data="<Customers><Customer ID="1" Name="cust1"/><Customer ID="2"
Name="cust2"/></Customers>";


Regards,
Mohamed Mosalem
 
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Xsl" %>
<%@ Import Namespace="System.Xml.XPath" %>

<script runat="server">

void Page_Load(object sender, System.EventArgs e)
{
string xmlPath = Request.PhysicalApplicationPath + @"file.xml";
string xslPath = Request.PhysicalApplicationPath + @"file.xsl";

XmlReader rdr = XmlReader.Create(xmlPath);
XslCompiledTransform transform = new XslCompiledTransform ();

//Load the XSL stylsheet into the XslCompiledTransform object
transform.Load(xslPath);

transform.Transform(rdr, null, Response.Output);
}
</script>
 
Back
Top