RE: [xsl] what I meant by preserving whitespace

Subject: RE: [xsl] what I meant by preserving whitespace
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 24 Sep 2001 12:18:57 -0400


It's good that you found the FO properties that provide for turning off whitespace-munging. It's not a tranform problem (as Chris's code showed), it's a problem of controlling your target tag set so the application does the right thing with it.

To indulge for a moment in markup-theoretical purism: to be completely in keeping with the way XML generally wants to look at white space, your source would not even contain whitespace that was significant as "data content" -- rather, you'd use markup to convey the information that is, in some kinds of visual media (such as print), conveyed by space. Accordingly, the prosodic features of a poem, for example, that are indicated by white space in their print rendition, would in an XML character stream be indicated by markup instead, as in

<line indent="double">Imagine this is a poem</line>
<line indent="single">and we want lines idented</line>
<line indent="single">in this strange fasion</line>

and so forth. This is the "clean" way to do it because it separates format from content -- downstream (say, in your XSLT) you can provide whatever whitespace you need to make it look right. (We could take this further: "real" markup of poetry might have even better ways to do it than using 'indent' attributes, which are actually only recording presentation. Often, in poetry, there are deeper structures, such as metrical or stanza structures, that drive the rendition and that can be represented through markup. But that's another topic.)

Of course, many or most applications aren't going to tolerate the kind of tag explosion that you'd get if you tried to do everything this way. Also, even this approach fails to get at some far-out cases, such as ASCII art (check out people's .sigs), or (say) Python code, where whitespace is actually part of the "data".

This is why XML has mandated the syntax for xml:space -- to allow XML applications to share a syntactical construct to say "hey, white space matters here, hands off". But XSLT leaves its hands off whitespace in text nodes anyway. You don't need to "implement" xml:space because it generally comes for free.

On the other hand, if you have an application like a web browser, that *doesn't* respect whitespace in the source when it puts it on screen (or an FO formatter that does helpful line wrapping, etc.), you have to work around that based on that application's features and foibles. This is what those FO properties are designed for.


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================

XSL-List info and archive:

Current Thread