You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by Drazen DOTLIC <Dr...@trema.com> on 2002/10/03 09:29:55 UTC

Selecting output encoding for xml -> TEXT transformation

OK, either I did too much explaining or I was not clear enough... I've
additionally traced the problem to the following: FormatterToText has
several constructors, of which only one is used during transformation,
and that one has the following:
...
m_encoding(isEmpty(encoding) == false ? encoding :
XalanDOMString(XalanTranscodingServices::s_utf8String)),
m_haveEncoding(true),
...
So, the problem is that "super default" is utf-8, which is IMHO wrong.
The reason why would be that when I pass plain string to the
XalanDOMString (say, in my extension function) it is being converted to
utf-16 (which is what Xalan internally uses) using transcode from local
code page, and that should also be super default when transcoding the
result of final transformation (only reverse should be done, of course,
transcode to local code page).
I suspect that not many people transform xml to TEXT, mainly they
transform to HTML, or XML, but not so much to text, so this "feature"
was not really discovered.

Can some of the contributors help me with this now? Am I still not
making sense?


> -----Original Message-----
> From: Drazen DOTLIC 
> Sent: Wednesday, October 02, 2002 3:29 PM
> To: xalan-c-users@xml.apache.org
> Subject: Selecting output encoding
> 
> 
> Hello,
> 
> I guess this is simple, but I've been debugging for two hours 
> now and still can't find what to do... The docs don't help either.
> 
> Here's what I do: I am transforming XML into text, and during 
> transformation I additionally have my own extension functions 
> called. The actual call I use is: transform (  const 
> XSLTInputSource & theInputSource,  
>  const XalanCompiledStylesheet * theCompiledStylesheet,  
>  const XSLTResultTarget & theResultTarget)
> 
> Result target is constructed with ostrstream, and then I just call
> ostrstream::str() to get the final result. Input source is 
> similar - uses istrstream initialized with the XML.
> 
> Everything works fine but when non-ASCII characters enter the 
> picture, it becomes complicated. My extension function gives 
> back to the processor a string that contains 
> non-breaking-space. XalanDOMString does implicit conversion 
> from local code page to Unicode, and that seems to work 
> exactly as it should, but even if non-breaking-space 
> translates into God-knows-which Unicode character, that would 
> still be fine (I
> assumed) because when spitting the result back to me, the same (but
> reverse) process would happen - Unicode string would be 
> transcoded back to my local code page (even though I am on 
> NT/XP). But, that is not the case :) Note that I am NOT 
> changing the string in any way in XSLT code itself. 
> Xalan always uses the encoding of the source file (I guess), 
> even if I manually set the encoding for the result target to 
> something other than utf-8 (which is the encoding of source 
> file). What am I missing here? Additionally, when doing final 
> transcode, XalanOutputStream checks to see if internal 
> pointer to transcoder is 0 and if it is, it does EXACTLY what 
> I want - it converts TO local code page. But internal 
> transcoder was previously already set to utf-8, and I see no 
> way to override this.
> 
> Thanks in advance for any help. Hopefully I will not have to 
> write my own XalanOutputHandler to resolve this :((
> 
> Regards,
> 
> Drazen
>