You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by sagara <sa...@aeturnum.com> on 2007/11/06 09:07:30 UTC

Exception when loading translet within a JSP

Hi all,

I try to use translets within a web application. My environment is tomcat
5.5 and jdk 1.5, I wrote a small JSP page and try to load compiled translet
class in to an input source and execute the transformation. Then I got
following error message. 

 

(Location of error unknown)
org.apache.xerces.impl.io.MalformedByteSequenceException : Invalid byte 2 of
2-byte UTF-8 sequence.

 

 

 

Here I have attached all required code for this example (here I used
absolute paths, but i tried for relative paths also).

 

Further, when I try same example as standalone application (with a main
method), it worked nicely and produce the output also.

  

Can some one help me to solve this? 

 

Thanks

Sagara 

 

 

 

 

//    JSP page 

//  String transletName = "e:/person.xsl";

    String transletName = "e:/person.class";

 

    String documentURI = "e:/person.xml";

    

      try {

          if ((transletName == null) || (documentURI == null)) {

              out.println("<h1>XSL transformation error</h1>");

            out.println("The parameters <b><tt>class</tt></b> and " +

                      "<b><tt>source</tt></b> must be specified");

          }

          else {

               TransformerFactory tf = TransformerFactory.newInstance();

               try {

                   tf.setAttribute("use-classpath", Boolean.TRUE);

               } catch (IllegalArgumentException iae) {

                   System.err.println(

                          "Could not set XSLTC-specific TransformerFactory "

                        + "attributes.  Transformation failed.");

               }

               Transformer t =

                        tf.newTransformer(new StreamSource(transletName));

 

            // Start the transformation

            final long start = System.currentTimeMillis();

            t.transform(new StreamSource(documentURI),

                           new StreamResult(out));

            final long done = System.currentTimeMillis() - start;

            out.println("<!-- transformed by XSLTC in "+done+"msecs -->");

          }

      }

      catch (Exception e) {

          out.println("<h1>Error</h1>");

          out.println(e.toString());

      }

 

 

 

 

 

 

 

 

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

            <xsl:template match="/">

                        <html>

                        <body>

                        <head><h1 align="center"> Person
Database</h1></head>

                        <table align="center">

                        <tr>

                                    <th bgcolor="yellow">Name</th>

                                    <th bgcolor="yellow">Email</th>

                                    <th bgcolor="yellow">Phone</th>

                        </tr>

                        <xsl:for-each select="Persons/Person">

                                    <tr>

                                                <!--xsl:variable
name="tempName" select="concat(Title,' ',First,' ',Last,' ')"/-->

                                                <td bgcolor="pink">

                                                            <xsl:value-of
select="Title"/>

                                                </td>

                                                <td bgcolor="pink">

                                                            <xsl:value-of
select="Email"/>

                                                </td>

                                                <td bgcolor="pink">

                                                            <xsl:value-of
select="Phone"/>

                                                </td>

                                    </tr>

                        </xsl:for-each>

                        </table>

                        </body>

                        </html>

            </xsl:template>

</xsl:stylesheet>

 


Re: Exception when loading translet within a JSP

Posted by Henry Zongaro <zo...@ca.ibm.com>.
Hi, Sagara.

Henry Zongaro/Toronto/IBM@IBMCA wrote on 2007-11-06 05:45:45 AM:
> "sagara" <sa...@aeturnum.com> wrote on 2007-11-06 03:07:30 AM:
> > I try to use translets within a web application. My environment is 
> > tomcat 5.5 and jdk 1.5, I wrote a small JSP page and try to load 
> > compiled translet class in to an input source and execute the 
> > transformation. Then I got following error message. 
> > 
> > (Location of error unknown) org.apache.xerces.impl.io.
> > MalformedByteSequenceException : Invalid byte 2 of 2-byte UTF-8 
sequence. 
> 
> That error message is reporting a problem in the encoding of an XML 
> document - probably your person.xml document.  Can you show us that 
document?

Now I see the problem.  In the following fragment, you've specifed the 
translet class file name in the StreamSource.  In fact, the argument to 
StreamSource should still be the URI for the stylesheet, even with the 
use-classpath argument.  XSLTC simply uses that URI to determine the name 
of the translet class, and as long as the "person" translet class (and any 
of its ancillary classes) are on the class path, XSLTC will find them 
without recompiling the stylesheet.  If it fails to find them, XSLTC will 
report an error.

"sagara" <sa...@aeturnum.com> wrote on 2007-11-06 03:07:30 AM:
> //    JSP page 
> //  String transletName = "e:/person.xsl";
>     String transletName = "e:/person.class";
[HZ:Deleted some code]
>                TransformerFactory tf = TransformerFactory.newInstance();
>                try {
>                    tf.setAttribute("use-classpath", Boolean.TRUE);
>                } catch (IllegalArgumentException iae) {
>                    System.err.println(
>                           "Could not set XSLTC-specific 
TransformerFactory "
>                         + "attributes.  Transformation failed.");
>                }
>                Transformer t =
>                         tf.newTransformer(new 
StreamSource(transletName));

I hope that helps.

Thanks,

Henry
------------------------------------------------------------------
Henry Zongaro      XSLT Processors Development
IBM SWS Toronto Lab   T/L 313-6044;  Phone +1 905 413-6044
mailto:zongaro@ca.ibm.com

Re: Exception when loading translet within a JSP

Posted by Henry Zongaro <zo...@ca.ibm.com>.
Hi, Sagara.

"sagara" <sa...@aeturnum.com> wrote on 2007-11-06 03:07:30 AM:
> I try to use translets within a web application. My environment is 
> tomcat 5.5 and jdk 1.5, I wrote a small JSP page and try to load 
> compiled translet class in to an input source and execute the 
> transformation. Then I got following error message. 
> 
> (Location of error unknown) org.apache.xerces.impl.io.
> MalformedByteSequenceException : Invalid byte 2 of 2-byte UTF-8 
sequence.

That error message is reporting a problem in the encoding of an XML 
document - probably your person.xml document.  Can you show us that 
document?

Thanks,

Henry
------------------------------------------------------------------
Henry Zongaro      XSLT Processors Development
IBM SWS Toronto Lab   T/L 313-6044;  Phone +1 905 413-6044
mailto:zongaro@ca.ibm.com