[XML4Lib] delivering xml thru the server
Araby Y Greene
araby at unr.edu
Thu Nov 30 15:48:56 EST 2006
If you are using ASP.Net (not classic ASP), you could pass the xmlPath and xslPath to your script instead of hardcoding it, as in the example below.
If this script was saved as xtransform.aspx, using an xml file (in the same directory) named "newbooks.xml" and an xsl file named "new.xsl", you could link to it like this:
http://www.library.unr.edu/new/xtransform.aspx?xml=newbooks.xml&xsl=new.xsl
(in your anchor tag, escape the "&" as "&")
If the files are not in the same directory, you'd need to modify the xmlfile variable to include the path:
http://www.library.unr.edu/new/rsstnew.aspx?xml=/ebooks/newbooks.xml&xsl=new.xsl
If you link to the .xsl file from within the .xml file, the server will not do anything with it. There are some javascript solutions that others may use. Almost all of our ASP.Net transforms are done from database queries, but I saved this basic script (that works well) "just in case." Aggregators don't seem to care about the file extension being .aspx instead of .xml or .rss.
<%@ Page Language="CS"%>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Xsl" %>
<%@ Import Namespace="System.Xml.XPath" %>
<script runat="server">
public void Page_Load(Object sender, EventArgs e) {
string xmlfile = Request["xml"];
string xslfile = Request["xsl"];
string xmlPath = Server.MapPath(xmlfile);
string xslPath = Server.MapPath(xslfile);
//Instantiate the XPathDocument Class
XPathDocument doc = new XPathDocument(xmlPath);
//Instantiate the XslTransform Class
XslTransform transform = new XslTransform();
transform.Load(xslPath);
//Custom format the indenting of the output document
//by using an XmlTextWriter
XmlTextWriter writer = new XmlTextWriter(Response.Output);
//If the next line wraps in your e-mail, make sure you put it back together
writer.WriteDocType("html", "-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", null);
writer.Formatting = Formatting.Indented;
writer.Indentation=4;
transform.Transform(doc, null, writer);
}
</script>
Hope this gives you some ideas if it doesn't help!
-araby
__________________________
Araby Greene
Web Development Librarian
Getchell Library/322
University of Nevada, Reno
http://www.library.unr.edu/
araby at unr.edu
775.784.6500 x343
/|
\'o.O'
=(___)=
U
ACK! THPTPHH!
________________________________________
From: xml4lib-bounces at webjunction.org [mailto:xml4lib-bounces at webjunction.org] On Behalf Of Pierre Nault
Sent: Thursday, November 30, 2006 10:56 AM
To: xml4lib at webjunction.org
Subject: [XML4Lib] delivering xml thru the server
Greetings,
I have a lot of xml documents on a web server (Windows2000) with xslt stylsheets. I'm executing the transformations (XSLT) on the server with an asp file for each xml document and send back an HTML document. I have to create an asp file for each document indicating the xslt stylsheet... I'm not familiar with the management of a web server but I think it's possible to simplify the way I'm doing the transformations. Specially in making all these asp files and having to refer, in the URI, to an asp extension instead of the xml one. Instead of making all these asp files, I was wondering if there is a way to "tell" the server that, when there is an xml file called by a client, to do the transformation with a specific xslt stylsheet ?
Thank you
Pierre Nault
Bilbiothécaire de référence
Service des bilbiothèques de l'UQAM
--
What do you call a cyclist who doesn't wear a helmet? An organ donor. ~David Perry
More information about the XML4Lib
mailing list