Subject: Re: [xsl] Transformation using Saxon.Net-1.0-RC1 From: "M. David Peterson" <m.david.x2x2x@xxxxxxxxx> Date: Wed, 30 Mar 2005 12:07:38 -0700 |
Hi Arthur, I've been away for the last 18 hours and am just noticing this email. I have some examples posted to the weblog. > http://weblog.saxondotnet.org Its true that with the latest version of IKVM compiler and runtime you no longer need the ByteArrayHack to get things to work. Here is the updated way to write the support class in C# (the same one listed on the weblog): using System; using System.IO; using System.Xml; using javax.xml.transform; using javax.xml.transform.stream; using net.sf.saxon; namespace org.x2x2x.Xml { public class Xsl { public static string Transform(string inXML, string inXSL){ StreamSource inputXml_Source = new StreamSource(new java.io.FileInputStream(inXML)); inputXml_Source.setSystemId(inXML); StreamSource inputXsl_Source = new StreamSource(new java.io.FileInputStream(inXSL)); inputXsl_Source.setSystemId(inXSL); return DoTransform(inputXml_Source, inputXsl_Source); } private static string DoTransform(StreamSource Xml, StreamSource Xsl){ java.lang.System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl"); StreamResult outResult = new StreamResult(); java.io.ByteArrayOutputStream outputXmlResult = new java.io.ByteArrayOutputStream(); outResult.setOutputStream(outputXmlResult); TransformerFactory trans = TransformerFactory.newInstance(); Transformer transformer = trans.newTransformer(Xsl); //transformer.setParameter("dir", "output"); transformer.transform(Xml, outResult); return outputXmlResult.toString(); } } } Let me know if you have any further issues and I will be happy to get you going in the right direction. Cheers, <M:D/> On Wed, 30 Mar 2005 04:54:32 +0100, Arthur Maloney <ArthurM@xxxxxxxxxx> wrote: > Hello , > > For basic learning purpose, I'm trying to do a simple transformation, so that next Saturday I can buy MK's > books, and then get down to the business of using XSL2/XPath with C# (Hoping to > move on from VB & MSXML.). > > First it does not compile. > > Error message 'ikvm.lang.ByteArrayHack' is obsolete > > Note: Before starting I installed J2SE 5.0 Update 2(jdk1.5.0_02) > > Is this to up-todate?? > > If I comment this out, it compiles. Stepping through the code gives error > Exception Details: javax.xml.transform.TransformerConfigurationException: Failed to parse stylesheet > > An example of a working transformation would help. > > -- > Best regards, > Arthur > > For completeness my Code is below > (from example provided by Saxon.NET-ASP.NET-Sample) > > <?xml version="1.0" encoding="utf-8" ?> > <saxondotnet_sample> > <message>Hello ASP.NET!</message> > </saxondotnet_sample> > > <?xml version="1.0" encoding="UTF-8" ?> > <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > <xsl:output method="html"/> > <xsl:template match="/"> > <xsl:apply-templates select="saxondotnet_sample/message"/> > </xsl:template> > <xsl:template match="message"> > <xsl:value-of select="."/> > </xsl:template> > </xsl:stylesheet> > > In the bin Directory > Compile.exe > IKVM.GNU.Classpath.dll > IKVM.Runtime.dll > Query.exe > Saxon.NET.dll > Transform.exe > > /*************************************************/ > /****** BEGIN Page Class ********/ > /*************************************************/ > > using System.Collections.Specialized; > using System.Collections; > using System.ComponentModel; > using System.Configuration; > using System.Data.SqlClient; > using System.Data; > using System.Drawing; > using System.IO; > using System.Text.RegularExpressions; > using System.Text; > using System.Web.Caching; > using System.Web.Security; > using System.Web.SessionState; > using System.Web.UI.HtmlControls; > using System.Web.UI.WebControls; > using System.Web.UI; > using System.Web; > using System.Xml.Xsl; > using System.Xml; > using System; > > //Saxon.Net > using javax.xml.transform; > using javax.xml.transform.stream; > using net.sf.saxon; > > namespace SaxonNet > { > > // Class for web page pgeSecond.aspx > public class pgeSecond : Page > { > // Declare controls on the HTML page. > protected Button btn; > > // default constructor > public pgeSecond() > { > Page.Init += new System.EventHandler(Page_Init); > } > > private void Page_Init(object source, EventArgs e) > { > InitializeComponent(); > } > > private void InitializeComponent() > { > // wire up the event handlers > this.btn.Click += new EventHandler( this.btn_Click ) ; > this.Load += new EventHandler(this.Page_Load); > } // InitializeComponent > > private void Page_Load(object source, EventArgs e) > { > > if (! IsPostBack) > { > // code goes here > } > } // Page_Load > > private void btn_Click(object source, EventArgs e) > { > string xmlSource = "index.xml"; > string xslSource = "index.xslt"; > string transform; > > // instantate new class object > Xsl xsl=new Xsl(); > > transform = xsl.Transform(Server.MapPath(xmlSource), Server.MapPath(xslSource)); > } > > } // end of pgeSecond > > public class Xsl > { > private string strCrLf = "\r\n"; > > // constructor > public Xsl(){} > > public string Transform(string inXML, string inXSL) > { > StreamSource inputXml_Source = new StreamSource(new java.io.FileInputStream(inXML)); > inputXml_Source.setSystemId(inXML); > StreamSource inputXsl_Source = new StreamSource(new java.io.FileInputStream(inXSL)); > inputXsl_Source.setSystemId(inXSL); > return DoTransform(inputXml_Source, inputXsl_Source); > } > > private string DoTransform(StreamSource Xml, StreamSource Xsl) > { > java.lang.System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl"); > StreamResult outResult = new StreamResult(); > java.io.ByteArrayOutputStream outputXmlResult = new java.io.ByteArrayOutputStream(); > outResult.setOutputStream(outputXmlResult); > TransformerFactory trans = TransformerFactory.newInstance(); > Transformer transformer = trans.newTransformer(Xsl); > transformer.setParameter("dir", "output"); > transformer.transform(Xml, outResult); > string strFinal = System.Text.UTF8Encoding.UTF8.GetString(ikvm.lang.ByteArrayHack.cast(outputXmlResult.toByteArray())); > return strFinal += strCrLf; > } > } // end Xsl > } // end of namespace > > /*************************************************/ > /****** END Page Class ********/ > /*************************************************/ > > /*************************************************/ > /****** BEGIN HTML Page ********/ > /*************************************************/ > > <%@ page inherits="SaxonNet.pgeSecond" src="second.aspx.cs" AutoEventWireup="false" debug="true" %> > <html> > <head> > <title></title> > > </head> > > <body> > <form id="frmMain" runat="server" method="post"> > <asp:Button id="btn" runat="server" > text="Test"/> > </form> > </body> > </html> > > /*************************************************/ > /****** END HTML Page ********/ > /*************************************************/ > > -- > Best regards, > Arthur mailto:ArthurM@xxxxxxxxxx > > -- <M:D/> :: M. David Peterson :: XML & XML Transformations, C#, .NET, and Functional Languages Specialist
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Transformation using Saxon.Ne, Arthur Maloney | Thread | Re[2]: [xsl] Transformation using S, Arthur Maloney |
RE: [xsl] node positioning problem, Michael Kay | Date | RE: [xsl] Testing 2 XML documents f, anton |
Month |