This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: losing significant whitespace with normalize-space
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: "Bradford, Denis" <denisb at rational dot com>
- Cc: "'XSL-List at lists dot mulberrytech dot com'" <XSL-List at lists dot mulberrytech dot com>
- Date: Tue, 16 Jul 2002 20:46:12 +0100
- Subject: Re: [xsl] losing significant whitespace with normalize-space
- Organization: Jeni Tennison Consulting Ltd
- References: <3906C56A7BD1F54593344C05BD1374B1053EB6A0@SUS-MA1IT01>
- Reply-to: xsl-list at lists dot mulberrytech dot com
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 
 or 
 characters with spaces:
<xsl:template match="text()">
<xsl:value-of select="translate(., '

', ' ')" />
</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