When trying to determine programmatically the encoding of the result of the following DOM+XSLT_FILE->SERVLET_RESPONSE_WRITER parse:

transformer = tFactory.newTransformer(xslSource);
transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
transformer.transform(new DOMSource(doc), new StreamResult(out));

I'm getting a incorrect <META> tag on the (html) result :

<META http-equiv="Content-Type" content="text/html; charset=UTF-8">

But if I select explicitly the output method by:

1.- Adding another OutputProperty

    transformer.setOutputProperty(OutputKeys.METHOD, "html");

or 2.- Setting the correct output instruction on my xslt file

    <xsl:output method="html" encoding="ISO-8859-1" indent="no"/>
   
I get the correct

<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

I know (now :-)  there are a couple of  checks like  the following one on xalan's code:

if (null == format)
{
   format = OutputPropertiesFactory.getDefaultMethodProperties(Method.XXX);
                                                                                      // where XXX is XML or HTML or ...
}
so (I guess) my encoding  was overwrited by one of those variables defined on output_xxx.properties file since I hadn't specified the output method.

But ... even if I didn't set the method to use -XML, HTML, Text -  the  parser figured it out well (meta tag from ToHTMLStream appears ) so ... why don't respect the encoding then?.
I could accept the overwriting value on the properties I've not set or if the method to use is not correctly determined by the parser , but I feel a little odd this ALL - NOTHING behaviour. Is this the expected behaviour?. I'm missing something?. Is the OutputKeys.METHOD expected to be always defined?. Some light about this point would be great.

Environment :
Xalan 2.7.0
JRE  1.4.1_06
App Server  JRun 4.0 build 92909

--
Regards,
Aitor Garcia
http://fco.textdriven.com

Reply via email to