This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: outputting spaces in html table cells
- To: xsl-list at mulberrytech dot com
- Subject: Re: outputting spaces in html table cells
- From: Mike Brown <mike at skew dot org>
- Date: Mon, 28 Aug 2000 10:07:10 -0600 (MDT)
- Reply-To: xsl-list at mulberrytech dot com
"Sellmer-Brüls, Barbara" wrote:
> I solved it with the following toplevel XSL elements:
> <xsl:preserve-space elements="*"/>
I'm not sure how this really solves your problem. All this does is makes
it so that none of the whitespace-only text nodes in your source tree are
stripped before processing. This lets you have the string-value of element
'blah' be a whitespace-only string, if it is specified as such in the XML,
instead of an empty string. But if all you are doing is this:
<td class="listing"> <xsl:value-of select="blah" /> </td>
then you have said "create an element 'td' with attribute
'class'='listing', and create a text node child with ' ' followed by a
text node with the string-value of element 'blah' followed by a text
node with another ' ':
element 'td'
| \___attribute 'class'='listing'
|___text ' '
|___text '' (string(blah))
|___text ' '
Following the rules of the XPath/XSLT data model, the 3 text nodes will be
combined into 1, which will be ' ' at the very least, and you know it
will be nothing but whitespace if blah was empty or had a whitespace-only
string-value:
element 'td'
| \___attribute 'class'='listing'
|___text ' '
When serialized as HTML as per the xsl:output method specified, you get
<td class="listing"> </td>
Following the rules of HTML, adjacent spaces are collapsed and considered
to be 1 single 'word separator', and in this case there are no words to
separate, so it will be collapsed entirely, producing the same result as
<td class="listing"></td>
...which of course is technically not allowed, and I think is why you want
to use . is by definition  , so as long as you put
  into the result tree, you will get either   or in the
HTML. Here is my suggestion:
<td class="listing">
<xsl:choose>
<xsl:when test="normalize-space(blah)">
<xsl:value-of select="blah"/>
</xsl:when>
<xsl:otherwise> </xsl:otherwise>
</xsl:choose>
</td>
- Mike
____________________________________________________________________
Mike J. Brown, software engineer at My XML/XSL resources:
webb.net in Denver, Colorado, USA http://www.skew.org/xml/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list