[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: How to read the encoding of an XML document

Subject: Re: How to read the encoding of an XML document
From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx>
Date: Thu, 25 Oct 2001 14:46:26 -0400
xslt read encoding
[James Garriss]


> If I no longer know what my original XML document was encoded as, how do I
> know the appropriate encoding set to specify for the output?
>
>   In XML I was going to do xsl:output encoding="whatever the input xml
was"
>
>   In HTML I was going to do META content="text/xml; charset=whatever the
> input XML was"
>

As you can tell  by now, if you want to get the original encoding you have
to get it from the document separately from any xslt transformation.
Another point to think about is that sometimes an encoding declaration is
mistaken and the document actually contains illegal characters for the
claimed encoding.  An xml parser (or the xslt processor's front end) will
catch that.

Given that you have to do something outside of a stylesheet, here's the
simplest thing I can think of.  Create a set of identity transform
stylesheets (check the FAQs if you aren't sure how to do that), each one
with a different output encoding that you wish to support.  Capture the
encoding with a separate non-xslt program.  After you run the main
transformation,  run the result through the right identity transform,
selected based on the encoding you captured.

This might be slow on large files, though, since two files will have to be
parsed and transformed.

Another approach is to dynamically build the stylesheet before use, changing
only the encoding, again using non-xslt methods.  This would be very easy
and fast.  You would use the encoding you discovered to build the stylesheet
version you wanted.

Are you sure you don't just want to output utf-8 and be done with it?

Cheers,

Tom P


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.