Fw: whitespace

Subject: Fw: whitespace
From: "Oren Ben-Kiki" <oren@xxxxxxxxxxxxx>
Date: Tue, 26 Jan 1999 10:18:45 +0200
Frank Boumphrey <bckman@xxxxxxxxxxxxx> wrote:

>>>Is there any good way to control whitespace in the html output from
>>>msxml.dll,
>
>The only way I've found to do it is to use the HTML namespace and a PRE
tag!
>
> CSS white-space:pre, and the attribute xml:whitespace="preserve' don't
seem
>to work.


They don't work for me, either. If you are interested in controlling
whitespace outside a <PRE> tag - that is, you want your HTML to look
reasonably nice - you can do the following:

1. Write your XSL in the following style:

<xsl:template match="InputElement"
    ><xsl:element name="OutputElement"
        ><xsl:attribute name="OutputAttr"
            ...
        ></xsl:attribute
    ></xsl:element
></xsl:template

The trick is that all newlines and whitespace are contained inside '<' ...
'>' pairs and therefore are guaranteed to be ignored regradless of any
whitespace handling flags and strange XSL processor behaviours.

2. Write your xml document the same way. Actually, if the XML document is
generated by a program, you can simply generate a single long line without
any spaces or newlines between elements. They may still appear in element
contents, of course.

Now you have full control over what's coming in the output. You'll have to
sprinkle the XSL stylesheet with rules to emit newlines here and then; I
always insert a newline before the content of each <xsl:element> and after
the </xsl:element>, which means the output should always look like this:

<HTML>
<HEAD>
...
</HEAD>
<BODY STYLE="...">
...
</BODY>
</HTML>

Actually, XT emits _some_ of these newlines by itself - not all - but
specifying them explicitly doesn't cause two consecutive newlines to be
emitted; they are merged somehow.

All this takes some time getting used to, and hapmers doing cut-and-paste
inside the xsl stylesheet (some lines start with '>', some with '/>', and
this depends on the line before them). But being able to read the results
makes it worth it.

If there's any way to avoid either (1) or (2), I'd love to know it.

Share & Enjoy,

    Oren Ben-Kiki


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


Current Thread