Re: [xsl] losing significant whitespace with normalize-space

Subject: Re: [xsl] losing significant whitespace with normalize-space
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 16 Jul 2002 20:46:12 +0100
Hi Denis,

> Using normalize-space is the only way I've found to eliminate the
> newlines, but then I lose the whitespace around the command elements
> is stripped.

That's because normalize-space() does three things:

  - replaces whitespace characters with spaces
  - strips leading and trailing whitespace
  - collapses sequences of whitespace into single spaces

It's the second of these that's causing you to lose whitespace. You
only want to do the first to get rid of the newline characters, so
instead of using normalize-space(), use the translate() function to
replace any &#xA; or &#xD; characters with spaces:

<xsl:template match="text()">
  <xsl:value-of select="translate(., '&#xA;&#xD;', '  ')" />
</xsl:template>
  
> The preserve-space (and strip-space) functions don't seem to have
> any effect, presumably because refpurpose is not a text-only
> element.

The xsl:preserve-space and xsl:strip-space elements govern how
whitespace-only text nodes are handled -- whether they're ignored or
preserved. In your document, the text nodes you're worried about have
other characters in them as well as whitespace, so they won't be
affected (although you'd be well advised not to use xsl:strip-space as
if you ever did have a whitespace-only text node within your
refpurpose, the likelihood is that you'd want to keep it).

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread