custom outputhandlers in xt (e.g. for wap phones)

Subject: custom outputhandlers in xt (e.g. for wap phones)
From: Tom Myers <tom.myers@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 08 Mar 2000 15:54:46 -0500
Oops, I'm answering my own question of yesterday,

>Subject: XT (XSLServlet) ignores media-type for xml?

but I think other people might be interested in the fact
that xt will happily call on custom output handlers
(written presumably as variations on the basic
  [HTML,XML,NXML,Text]OutputHandler
classes. So I'll mention the answer I found. I'd said

>I think I'm probably missing something obvious.
...
and that my xsl servlet could generate the right output with
  output method="xml"
or the right content-type with
  output method="html"
but couldn't do both with either.

I now find that I can write a custom XMLOutputHandler,
a slightly-modified version of that which jclark
includes, and call it by defining a namespace ("javaout")
which xt recognizes internally as the fixed string
  "http://www.jclark.com/xt/java";
and then use that namespace to label my outputhandler.
This outputhandler uses the media-type to set the content-type
of the response, and so in particular I can have an xsl
servlet produce text/vnd.wap.wml output, or presumably
any other. It goes like this, and appears very nicely on
the simulated WAP phone on my screen:

----------------------------------------
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:vdoc="http://www.jclark.com/xt/java/MyNa.jspUtil.QueryDoc";
  xmlns="http://www.w3.org/TR/xhtml1/strict";
  xmlns:javaout="http://www.jclark.com/xt/java";
  exclude-result-prefixes="javaout vdoc #default"
>
<xsl:output   method="javaout:MyNa.jspUtil.XMLOutputHandler"
  indent="yes" encoding="UTF-8"
    media-type="text/vnd.wap.wml" omit-xml-declaration="no"
    doctype-public="-//PHONE.COM//DTD WML 1.1//EN" 
    doctype-system="http://www.phone.com/dtd/wml11.dtd";
 />
<xsl:param name="theSessionID" select="NoHttpSessionIDProvided"/>
<xsl:template match="/">
<wml>
<head>
  <meta http-equiv="Cache-Control" content="no-cache" forua="true"/>  
</head>
<card id="output" title="TimeTemp">
....
</card>
</wml>
</xsl:template>
</xsl:stylesheet>
----------------------------------------
So maybe nobody else is doing this kind of thing, or maybe everybody
else who uses xt already knows how to do custom stuff like this, but
it took me a long time to figure it out (I had to recompile xt with
some logging code inserted) and I hope I'll save somebody some time,
sometime or other.

Tom Myers    tom.myers@xxxxxxxxxxxxxxxx


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


Current Thread