Re: [xsl] White space in HTML result??

Subject: Re: [xsl] White space in HTML result??
From: Mike Brown <mike@xxxxxxxx>
Date: Mon, 5 Feb 2001 21:49:43 -0700 (MST)
> <a>
> [...]
> </a>&#160;&#160;
>            </xsl:for-each>
> The problem is, after each </a> in the HTML page, there is x number of
> spaces.

Well this is expected, because after the 'a' element you have 2
non-whitespace characters and then a newline which is whitespace
and some spaces or tabs, which are also whitespace. Yes, I know
non-breaking spaces look like whitespace, but they aren't really.

The XPath/XSLT tree model insists that all adjacent text becomes
one text node, so you've got a text node containing all that text,
starting with the 2 non-breaking spaces. 

The model says that if the text node is nothing but whitespace,
it might be removed from the tree ('stripped') prior to processing.
If it's in the stylesheet it will always be stripped and you have
no control over this. If it's in the source tree, you have some
control that I won't go into here..

But this is academic since your text node is not purely whitespace.
This means you are stuck with it!

You just need to get the non-breaking spaces into a text node by
themselves. This will do it:

   <xsl:for-each ...>

Just be aware that it's not the fact that <xsl:text> is being used;
it's the fact that the non-breaking spaces are contained inside
*some* element, separate from the whitespace that comes at the end
of the contents of the xsl:for-each element.

   - Mike
Mike J. Brown, software engineer at            My XML/XSL resources: in Denver, Colorado, USA    

 XSL-List info and archive:

Current Thread