RE: Whitespace problem in IE5

Subject: RE: Whitespace problem in IE5
From: Dave Dieno <daved@xxxxxxxxxxxx>
Date: Thu, 20 May 1999 10:14:34 -0700
FYI:

I managed to work around the problem in IE5 with some help from MSDN (see
Controlling Whitespace :
http://msdn.microsoft.com/xml/xslguide/xsl-whitespace.asp ).

If you want to preserve the whitespace in your source document you have to
specify the following attribute for those source document elements with
whitespace, for example:

	<sourceline xml:space="preserve">

This passes the whitespace through to the stylesheet.

However, it seems that in IE5 the <xsl:value-of> element strips the leading
whitespace.   When I looked at the text value of the <sourceline> node using
Jscript and the DOM I found a workaround.

<xsl:template match="sourceline">
    <xsl:eval> getText(this) </xsl:eval>
</xsl:template>

<xsl:script><![CDATA[
  function getText(e) {
    return (e.text);
}

Not very elegant, but it works :)

Cheers,
Dave


> I haven't tried this, but I seem to remember its coming up before. If I
> recall, the solution is to use an <xsl:text> element to force the spaces.
> Something like:
> 
> 	<PRE><xsl:text>     </xsl:text>Indented text</PRE>
> 
> Worst case would be to use entity references for non-breaking spaces.
> 
> Hope that helps,
> John
> 
> At 09:12 PM 05/19/1999 -0700, Dave Dieno wrote:
> >Yes, the HTML is placed in a <PRE> section... sorry, I should have
> included
> >the XSL template:
> >
> ><xsl:template match="sourceline">
> > <PRE STYLE="font-family:monospace">
> >      <xsl:value-of />
> >  </PRE>
> ></xsl:template>
> >
> >I've also considered (but not tried) using the DTD approach I.E.
> <!ATTLIST
> >sourceline xml:space="preserve"> however I'm trying not to use a DTD for
> >this project :) 
> >Dave
> >
> >	Steve Dahl wrote:
> >
> >> When you generate the HTML, do you put these text lines inside a <PRE>
> >> section?
> >> 
> >> XML's specifications control how XML is treated, but not how HTML is
> >> treated--HTML strips preceding and following whitespace unless the text
> is
> >> in
> >> a <PRE>, and does not pay attention to xml:space.
> >> 
> >> 
> >> Dave Dieno wrote:
> >> 
> >> > I'm transforming XML to HTML via XSL using IE5.
> >> >
> >> > I've got an XML element for which I would like to preserve the
> >> whitespace
> >> > upon output to HTML.
> >> >
> >> > For example, I'd like the following XML fragment:
> >> >
> >> > <codelisting>
> >> > <sourceline>
> >> >     if ( x  ==    "testcase") {
> >> > </sourceline>
> >> > <sourceline>
> >> >         o.method(x);
> >> > </sourceline>
> >> > <sourceline>
> >> >     }
> >> > </sourceline>
> >> > </codelisting>
> >> >
> >> > Viewed in the browser as:
> >> >
> >> >     if ( x  ==    "testcase") {
> >> >         o.method(x);
> >> >     }
> >> >
> >> > My output font is monospaced, and I've tried using both the
> stylesheet
> >> > attribute:
> >> >
> >> > <xsl:stylesheet default-space="preserve"> and the element attribute:
> >> >
> >> > <sourceline xml:space="preserve">.
> >> >
> >> > What I get is:
> >> >
> >> > if ( x  ==    "testcase") {
> >> > o.method(x);
> >> > }
> >> >
> >> > While the whitespace within a line is preserved, all of the leading
> >> > whitespace characters (spaces and tabs) are removed :(
> >> >
> >> > Any ideas?
> >> >
> >> > Thanks,
> >> > Dave Dieno
> >> > Aeroinfo Systems Inc.
> >> > http://www.aeroinfo.com
> >> >
> >> >  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> >> 
> >> --
> >> - Steve Dahl
> >> sdahl@xxxxxxxxxxx
> 
> ==========================================================
> John E. Simpson            | The secret of eternal youth
> simpson@xxxxxxxxxxx        | is arrested development.
> http://www.flixml.org      |  -- Alice Roosevelt Longworth
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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


Current Thread