I have formatted text (with newlines, tabs, etc.) coming in from a Telnet connection. I have a python script that manages the Telnet connection and embeds the Telnet response in XML that then gets passed through an XSLT transform. How do I pass that XML through the transform without losing the original formatting? I have access to the transformation script and the python script but not the transform invocation itself.
A:
You could embed the text you want to be untouched in a CDATA section.
Alex Martelli
2009-06-19 00:07:37
Embedding the pre-formatted text in CDATA right at the beginning (in the python code that generates the initial XML seems to have done the trick. The newlines were still there when the final conversion to an HTML <PRE> tag was done.
Mark
2009-06-22 15:17:33
A:
Data stored in XML comes out the same way it goes in. So if you store the text in an element, no whitespace and newlines are lost unless you tamper with the data in the XSLT.
Enclosing the text in CDATA is unnecessary unless there is some formatting that is invalid in XML (pointy brackets, ampersands, quotes) and you don't want to XML-escape the text under any circumstances. This is up to you, but in any case XML-escaping is completely transparent when the XML is handled with an XML-aware tool chain.
To answer your question more specifically, you need to show some input, the essential part of the transformation, and some output.
Tomalak
2009-06-19 08:33:52