Subject: RE: [xsl] Microsoft xslt engine, calling from c# From: Pieter Reint Siegers Kort <pieter.siegers@xxxxxxxxxxx> Date: Fri, 25 Jun 2004 09:39:09 -0500 |
OK, when you say C# it means they are using .NET and in .NET there's strong support for XML and XSLT. They should be using the System.Xml and System.Xsl namespaces. You simply add these namespaces at the top of your code page: using System.Xml; using System.Xml.Xsl; I'll demonstrate its ease of use with an example below in C#, doing a XSLT during the Page_Load event of a Web Forms page: private void Page_Load(object sender, System.EventArgs e) { string strUrlXmlTemplateArticle = "http://" + System.Configuration.ConfigurationSettings.AppSettings["strLocalHost"] + "/docnet2/templates/XML_LstArtPorCatPrim5Resp.xml"; XmlDocument doc = new XmlDocument(); doc.Load(strUrlXmlTemplateArticle); /// in case you want to save the query result for viewing, /// remove the comment of the next five lines /* XmlTextWriter writer = new XmlTextWriter(Server.MapPath("/docnet/xml/XML_LstArtPorCatPrim5Resp.xml"), System.Text.Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.Indentation = 2; doc.Save(writer); writer.Close(); */ XmlOD.Document = doc; /// this approach works because the file dependency /// on the XSL Stylesheet makes ASP.NET automatically remove /// the chached stylesheet once the source changes XmlOD.Transform = (XslTransform)Cache["aplXslTransform"]; } Note that this example uses SQLXML to get data from the DB in XML format, but you can also simply use a path to your filename (the XmlDocument Load() method can read from a XmlReader, textReader, Stream, or directly from a file). In addition, XmlOD is the XML Web Control, defined as <asp:xml id="XmlOD" runat="server"></asp:xml> in the HTML code page (design). Another example could make use of the XslTransform class. It's use is simple: private void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) { string strConn = "DSN=doc351"; string strSQL = "SELECT ArticuloId,CategoriaId,Titulo,Fecha,Referencia FROM Articulo"; string xslPath = Server.MapPath("/DocM/xsl/articulos.xsl"); OdbcConnection objConn = new OdbcConnection(strConn); DataSet ds = new DataSet(); XslTransform transform = new XslTransform(); OdbcDataAdapter objDA = new OdbcDataAdapter(strSQL, objConn); objDA.Fill(ds, "Articulo"); XmlDocument doc = new XmlDocument(); doc.LoadXml(ds.GetXml()); transform.Load(xslPath); transform.Transform(doc, null, Response.OutputStream); } } The above sample uses the ODBC driver to access MySQL, read the data, expose it as XML, and do the XSLT; finally, its output is returned into the output stream to the browser. It shows how easy and powerful the .NET XML support really is. HTH, <prs/> -----Original Message----- From: David.Pawson@xxxxxxxxxxx [mailto:David.Pawson@xxxxxxxxxxx] Sent: Friday, June 25, 2004 8:58 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: [xsl] Microsoft xslt engine, calling from c# Hello Pieter Why would you call a COM component instead of using .NET's System.Xml and System.Xml.Xsl namespaces? The only reason I could think of is the better performance of MSXML over XslTransform... <grin/> Because its the only MS version of xslt that I know? If there is a better way, please let me know and I'll pass it on. regards DaveP -- DISCLAIMER: NOTICE: The information contained in this email and any attachments is confidential and may be privileged. If you are not the intended recipient you should not use, disclose, distribute or copy any of the content of it or of any attachment; you are requested to notify the sender immediately of your receipt of the email and then to delete it and any attachments from your system. RNIB endeavours to ensure that emails and any attachments generated by its staff are free from viruses or other contaminants. However, it cannot accept any responsibility for any such which are transmitted. We therefore recommend you scan all attachments. Please note that the statements and views expressed in this email and any attachments are those of the author and do not necessarily represent those of RNIB. RNIB Registered Charity Number: 226227 Website: http://www.rnib.org.uk --+------------------------------------------------------------------ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/ or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx> --+--
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Microsoft xslt engine, ca, David . Pawson | Thread | RE: [xsl] Microsoft xslt engine, ca, David . Pawson |
RE: [xsl] i18n problem while displa, Passin, Tom | Date | RE: [xsl] Microsoft xslt engine, ca, David . Pawson |
Month |