Ok..I got some good news and bad news in my dilema. Using the
setSystemId(getServletContext().getRealPath(XSLFilename)); has indeed given
the right path when trying to access the xsl. However, for some unknown
reason I am STILL seeing it say:

Error at xsl:include on line 5 of
file:/C:/orion/C:/app/www/inside/ob/search.xsl:
C:\orion\C:\app\www\inside\ob\include.xsl (The filename, directory name, or
volume label syntax is incorrect)
Exception while trying to transform document. MESSAGE = Failed to compile
stylesheet. 1 error detected.

I also tried setting the setPublicId() the same way. That didn't do anything
at all. So, I am still unable to display the page because the include in the
xsl is not working. I am still looking around the specs, but if anyone has
ideas as to why this is still not working..I'd be appreciative of knowing.
Below is my pasted code that does the transform.


    StreamSource xslStream = null;
    StreamSource xmlStream = null;

    try
    {
      // r is a variable that contains the name of the "relative"
path/page.xsl
      // and path/page.xml files. r.getXSL() returns the path to the xsl
page, and
      // r.getName() is the XML path page.
      File f = new File(getServletContext().getRealPath(r.getXSL()));  
      xslStream = new StreamSource(new FileReader(f));
    }
    catch(Exception e)
    {
      e.printStackTrace(System.out);
      System.out.println("Exception " + e.getMessage());
    }

    // Transform the xml output using the xsl stylesheet and the SAXON XSLT
    // engine, placing the output stream of the transformation in the
    // HttpServletResponse output stream.

    response.setContentType("text/html"); // always assume HTML output from
this controller

    try
    {
      // read in the JSP output by establishing a URL connection to the JSP
page, passing to it the session id.
      // the use of getScheme() and getServletName() is to make a complete
URL name.
      URL url = new URL(request.getScheme() + "://" +
request.getServerName() + r.getName() + "?jsessionid=" +
request.getSession(true).getId());
      xmlStream = new StreamSource(url.openConnection().getInputStream());

      TransformerFactory tFactory = TransformerFactory.newInstance();
      xslStream.setPublicId( getServletContext().getRealPath(r.getXSL()) );
// try this or the one below it or both but still does not fix the problem
      xslStream.setSystemId( getServletContext().getRealPath(r.getXSL()) );
      Transformer transformer = tFactory.newTransformer(xslStream);
      transformer.transform(xmlStream, new
StreamResult(response.getOutputStream()));
    }
    catch(Exception e)
    {
      e.printStackTrace(System.out);
      System.out.println("Exception while trying to transform document.
MESSAGE = " + e.getMessage());

      // attempt to forward to an error page
      try
      {
 
getServletContext().getRequestDispatcher("/no_mapping.jsp").forward(request,
response);
      }
      catch(Exception e2)
      {
      }
    }

Reply via email to