Lists Home |
Date Index |
- From: Mike Brown <firstname.lastname@example.org>
- To: 'rsanford' <email@example.com>
- Date: Wed, 23 Aug 2000 11:33:09 -0600
> can i use XSLT to convert xml data to/from fixed record data?
Without knowing the details of your fixed record data, it is not possible to
say whether XSLT is really a good tool for the job. Generally XSLT is better
for XML-to-(something XML-like), although "plain" text output in a given
encoding, using characters allowed in XML documents, is pretty easy to do.
Getting data into XML from fixed record data might be much easier to do with
a custom application. XSLT pretty much only lets you access XML files. You
could of course make a dummy file with an entity reference so that the
external file will be one giant text node:
<!DOCTYPE allTheData [
<!ELEMENT allTheData (#PCDATA)>
<!ENTITY theFile SYSTEM "data.txt">
...taking heed that if the encoding of data.txt is not declared with a text
declaration at the top of its file, and is not otherwise evident according
to the rules XML uses, then its encoding will be assumed to be UTF-8. This
will affect how the data is interpreted as characters by the XML parser that
is feeding information about the logical structures to the XSLT processor.
You have a limitation to work around in that the data model used by
XPath/XSLT does not acknowledge characters that are disallowed in XML
documents. The specs do acknowledge that the DOM can be used to manually
construct trees that contain wacky structures, but they don't acknowledge
that you could also use the DOM to create text with characters (or character
sequences) that would be illegal to have in XML documents. You might be able
to get away with it, but I wouldn't rely on it.
If you have an ultimate need to produce bytes that can't easily be derived
from the allowed characters (and it should be noted that most XSLT
processors only support a few output encodings), then you'll need to produce
something "close enough" and then post-process it.