XslCompiledTransform

  • Thread starter Thread starter Peter Kirk
  • Start date Start date
P

Peter Kirk

Hi

I am trying to exexute a transform (XslCompiledTransform .Transform), but
get this exception:

System.Text.EncoderFallbackException: Unable to translate Unicode character
\u2013 at index 3637 to specified code page.
at System.Text.EncoderExceptionFallbackBuffer.Fallback(Char charUnknown,
Int32 index)
at System.Xml.CharEntityEncoderFallbackBuffer.Fallback(Char charUnknown,
Int32 index)
....


What exactly is the cause of this, and how can I avoid it?

Thanks,
Peter
 
Peter Kirk wrote:

I am trying to exexute a transform (XslCompiledTransform .Transform), but
get this exception:

System.Text.EncoderFallbackException: Unable to translate Unicode character
\u2013 at index 3637 to specified code page.

What output encoding are you trying to transform to? It sounds as if the
result tree contains the Unicode character with hex code 2013 '–'
(decimal 8211) and that character is not contained in the code page you
want to use (e.g. with <xsl:output encoding="ISO-8859-1"> or
XmlWriterSettings) so serializing the result tree with the desired
encoding fails.
 
Martin Honnen said:
Peter Kirk wrote:



What output encoding are you trying to transform to? It sounds as if the
result tree contains the Unicode character with hex code 2013 '-' (decimal
8211) and that character is not contained in the code page you want to use
(e.g. with <xsl:output encoding="ISO-8859-1"> or XmlWriterSettings) so
serializing the result tree with the desired encoding fails.

Well see, I know virtually nothing about these aspects. I have been supplied
with an xslt file which contains this line:

<xsl:output method="text" encoding="iso-8859-1"/>

I have written a method which accepts an xml string (which consists of data
extracted from a database), and tries to transform this xml to csv format
using an xslt file (supplied by someone else). Could the problem be in the
"encoding" specified in the xslt? Or is it the xml data? What can I do to
avert the exception?

The transformation works with some data, but fails with other data. So it
appears there are some characters in some data which the transformation/xslt
cannot handle, but I don't really know where a fix for this should reside.

Thanks,
Peter
 
Peter Kirk wrote:

Well see, I know virtually nothing about these aspects. I have been supplied
with an xslt file which contains this line:

<xsl:output method="text" encoding="iso-8859-1"/>

I have written a method which accepts an xml string (which consists of data
extracted from a database), and tries to transform this xml to csv format
using an xslt file (supplied by someone else). Could the problem be in the
"encoding" specified in the xslt? Or is it the xml data? What can I do to
avert the exception?

The problem is that the XSLT stylesheet tries to output the character
'–' but that character is not contained in ISO-8859-1. Whether that
character is copied from the input or contained literally in the
stylesheet does not matter.

Use
<xsl:output method="text" encoding="UTF-8"/>
then you should not have any problems as UTF-8 as an Unciode encoding
can handle all Unicode characters.
Alternatively if you want text in a 8bit Windows code page then doing e.g.
<xsl:output method="text" encoding="Windows-1252"/>
should do, at least for that particular character you have shown:
<http://www.microsoft.com/globaldev/reference/sbcs/1252.mspx>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top