Re: [xsl] Fwd: Over/under trimming of whitespace

Subject: Re: [xsl] Fwd: Over/under trimming of whitespace
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Thu, 25 Apr 2002 23:52:39 +0200
like <td></td>, <td/>, and <td>-some whitespace-</td>

Between 1 and 2 there is know different.


I want an element with whitespace to do nothing and to generate an:
<fo:inline white-space-collapse="false"> </fo:inline>

I am using the following:

<xsl:choose>
  <xsl:when test="normalize-space()=' ' and .!=''">
    <fo:inline white-space-collapse="false"> </fo:inline>
  <xsl:/when>
<xsl:choose>

normalize-space() on an "empty" element returns an empty string. A text-node without any non-whitespace character will be removed completely using normalize-space(). So the test


<xsl:when test="normalize-space()">

is enough.

I have a couple of problems here, I thought that normalize-space() should return a single character if any whitespace exists. It appears to return an empty string, at least with SAXON. I am not sure if it
works internally with FOP because I don't get to see the intermediate fo
file.


The bigger problem is that specifying the following on a template rule that matches an element with whitespace
<fo:inline white-space-collapse="false"> </fo:inline>


becomes

<fo:inline white-space-collapse="false"/>

rendering this solution completely useless.

Whitespaces can be removed as far as I know.


I tried adding:

<xsl:preserve-space elements="fo:inline" />
>
> It doesn't appear to help.

This is only for the XML, not the XSLT.

The best thing is to use the non-breaking space character, which won't be removed. In XML/Unicode it's & #160; :

<fo:inline white-space-collapse="false">& #160;</fo:inline>

Regards,

Joerg


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



Current Thread