You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Michael Los <me...@mitre.org> on 2000/01/14 21:12:48 UTC

ApplyXSL enhancement request

In the file, ApplyXSL, for the servlet example, getContentType()
processes the media-type attribute of xsl:output to determine the
content type for the result.  I've pasted an enhancement to this method
below.  The enhanced method derives a default media-type value from the
method attribute if no media-type was found (as is the case with
default.xsl and default2.xsl provided with LotusXSL0_19_2).  Admittedly,
it doesn't follow all the fallback rules specified in Section 16 of the
XSLT spec since I don't have enough information to determine a default
if there is neither a method nor a media-type attribute.

If the content type is not specified, the browser may render the
returned HTML as text.  This is my experience while using Netscape
Navigator 4.7, Sun/Netscape iPlanet 4.0, JRun 2.3.3.

Michael Los
The MITRE Corporation



  public String getContentType(StylesheetRoot xslSourceRoot)
  {
    /* -----------------1/14/00 2:37PM-------------------
     * Original Lotus XSL code
    String encoding = xslSourceRoot.getOutputEncoding(), media =
xslSourceRoot.getOutputMediaType();
    if (encoding != null)
      return media + "; charset=" + encoding;
    return media;
     * --------------------------------------------------*/

    /* -----------------1/14/00 2:37PM-------------------
     * Modified by M. Los - MITRE
     * --------------------------------------------------*/
    String encoding = xslSourceRoot.getOutputEncoding();
    String media = xslSourceRoot.getOutputMediaType();
    if (media == null) {
      String method = xslSourceRoot.getOutputMethod();
      // if no media-type, try to derive it from the method
      if ( method != null ) {
        if ( method.equalsIgnoreCase( "html" )) {
          media = "text/html";
        } else if ( method.equalsIgnoreCase( "xml" ) ) {
          media = "text/xml";
        } else if ( method.equalsIgnoreCase( "text" ) ) {
          media = "text/plain";
        }
      }
    }
    if (encoding != null)
      return media + "; charset=" + encoding;
    return media;
  }