[xsl] Transformation using Saxon.Net-1.0-RC1

Subject: [xsl] Transformation using Saxon.Net-1.0-RC1
From: Arthur Maloney <ArthurM@xxxxxxxxxx>
Date: Wed, 30 Mar 2005 04:54:32 +0100
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,

 For completeness my Code is below
 (from example provided by Saxon.NET-ASP.NET-Sample)

<?xml version="1.0" encoding="utf-8" ?>
    <message>Hello ASP.NET!</message>

<?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 match="message">
    <xsl:value-of select="."/>

In the  bin Directory

/******                          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;

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)

        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));
      StreamSource inputXsl_Source = new StreamSource(new java.io.FileInputStream(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();
      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" %>


<form id="frmMain" runat="server" method="post">
<asp:Button id="btn" runat="server"

/******                          END  HTML Page                   ********/


Best regards,
 Arthur                          mailto:ArthurM@xxxxxxxxxx

Current Thread