Free since 2005 · No login required
AT

Academic Tutorials

Learn at your own pace

site-mobile-top-banner · 320x50

Why is the output character encoding I set in the stylesheet not being used?

If you use a character output stream to instantiate the StreamResult object which holds the transformation output, the Writer uses its own encoding, not the encoding you specify in the stylesheet. If you want to use the stylesheet output encoding, do not use StreamResult(java.io.Writer) to instantiate the holder for the output. Alternatively, you can specify the encoding when you create a Writer (java.io.OutputStreamWriter). Once the Writer exists, you cannot change its encoding. If the transformation is run in a servlet, it is possible that the Writer is coming from the ServletResponse object. If the stylesheet is run using the JAXP APIs and the Transformer's setOutputProperty() method is invoked, it is possible to set the "encoding" property and over-ride the value in the stylesheet.