XML, XSL and ASP.Net

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.
 
M

Mohamed Mosalem

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
 
D

djamilabouzid

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.
 
G

Guest

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
 
G

Guest

<%@ 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>
 

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,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top