[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: servlet and xml


Subject: Re: servlet and xml
From: "John McKeown" <mckeowj@xxxxxxxxx>
Date: Thu, 25 Mar 1999 12:54:50 -0000

Hello

I may be wrong about this but I believe the problem you are experiencing is
because you are generating an XML document in a Servlet (which is server
side, even when running on your machine) which references a stylesheet on
your local disk. The browser is complaining because the (downloaded)document
should not be able to access the local stylesheet.

I suggest you run a local Webserver on your machine which allows you to
access the Stylesheet using HTTP. I made the following change to your code
and got it to run.
out.println("<?xml:stylesheet type=\"text/xsl\"
href=\"http://mywebserv/test.xsl\"?");

I placed the stylesheet in the root driectory for my personal web server
(mywebserv), which allowed the downloaded document to access it.

Also, if you get this working you'll notice you're stylesheet results in a
blank screen. You need to change the reference <xsl:for-each
select="person[1]"> to <xsl:for-each select="person[0]"> since there is only
one element in the document returned by the servlet.

Hope that helps

John

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
John McKeown
Knowledge & Data Engineering Group
Department of Computer Science
O'Reilly Institute
University of Dublin, Trinity College

WWW: http://www.cs.tcd.ie/John.McKeown/
E-mail : mckeowj@xxxxxx
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
----- Original Message -----
From: Jayadeva Babu Gali <jayadeva@xxxxxxxxxx>
To: <Guy_Murphy@xxxxxxxxxx>; <xml-dev@xxxxxxxx>;
<xsl-list@xxxxxxxxxxxxxxxx>; Shekhar Kshirsagar
<skshirsa@xxxxxxxxxxxxxxxxxx>
Sent: Wednesday, March 24, 1999 12:40 PM
Subject: servlet and xml


>I am trying to dynamically creating an XML document with the Java
>Servlet and i am trying to style that XML information to the
>browser(IE5) using the static xsl document in the same directory where
>the servlet is there when i am trying to execute that servlet it is
>giving error like this
>Access is denied. Error processing resource
>'file://c:\servlets\test.xsl'.
>i am developing an xml application for that it is necessary to disply
>the xml document on the fly with static xsl.
>
>i am attaching  my servlet and xsl file
>
>can u please co-operate me
>
>regds...jayadev
>
>


----------------------------------------------------------------------------
----


>import java.io.*;
>import javax.servlet.*;
>import javax.servlet.http.*;
>
>/*
> * test Servlet sends back a simple, static XML page.
> */
>public class test extends HttpServlet
>{
>  public void doGet
>

>    HttpServletRequest  req,   // This provides information sent by the
browser
>    HttpServletResponse res    // This is used to send information back to
the browser
>  ) throws
>    ServletException,          // General exception that should be thrown
if there
>                               // is a unrecoverable error in the Servlet
>    IOException
>
>  {
>    // Set the MIME type for the information being sent to the browser.
>    // In this case, we are going to send back HTML
>
>       res.setContentType( "text/xml" );
>
>    // Get a reference to the output stream.
>    // Anything written to this stream is sent directly to the browser
>    // (The browser sees this as its input).
>
>       ServletOutputStream out = res.getOutputStream();
>
>    // The following println statements create an HTML page.
>    // Notice that the <html></html>, <head></head>, and <body></body>
>    // tags are all properly formed HTML syntax.
>       out.println("<?xml version=\"1.0\"?>" );
>       out.println("<?xml:stylesheet type=\"text/xsl\"
href=\"file:///c:/servlets/test.xsl\"?>");
>       out.println("<persons>");
>
out.println("<person><firstname>Oren</firstname><lastname>Ben-KiKi</lastname
></person>");
>       out.println("</persons>");
>
>  }
>
>}
>


----------------------------------------------------------------------------
----


><?xml version="1.0"?>
><xsl:stylesheet
>       xmlns:xsl="http://www.w3.org/TR/WD-xsl"
>       xmlns="http://www.w3.org/TR/REC-html40"
>       result-ns="">
>
>         <xsl:template match="/">
>         <HTML>
>          <HEAD>
>           <TITLE>Test</TITLE>
>          </HEAD>
>          <BODY>
>             <xsl:apply-templates/>
>          </BODY>
>        </HTML>
>        </xsl:template>
>        <xsl:template match="*">
>        <xsl:apply-templates/>
>        </xsl:template>
>
><xsl:template match="persons">
><xsl:for-each select="person[1]">
>   <h1><xsl:value-of select="firstname"/></h1>
>   <h1><xsl:value-of select="lastname"/></h1>
></xsl:for-each>
>        </xsl:template>
>        <xsl:template match="textnode()">
>        <xsl:value-of select="."/>
>        </xsl:template>
>
></xsl:stylesheet>
>
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords